header.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. window.checkData = []; //全选 数据池
  2. window.sort = require('../utilities/sort');//排序组件
  3. window.Header = function getHeader(object) {
  4. let _targetDom = object.el ? document.getElementById(object.el) : document.getElementsByTagName("table")[0];//基点元素
  5. let _columns = object.column; //列名
  6. let _fixedTop = object.fixedTop || 0; //同级浮动元素高度,使当前元素追加该元素高度浮动
  7. let _isCheckAllBox = object.isCheckAllBox !== false;//是否开启全选框
  8. let _data = object.data || []; //被排序数据
  9. let _restorationColumn = object.restorationColumn || 'id'; //恢复原数据基准字段
  10. let _isRestorationColumnAsc = object.isRestorationColumnAsc || false; //恢复原数据基准字段的排序类型 true:asc false:desc
  11. let _before = object.before;//前置元素
  12. let _name = "header:" + (object.name ? object.name + "." : "");//唯一名称 用于区别模块 本地存储
  13. let _isForbidDrag = object.isForbidDrag;
  14. let sortType = {}; //排序类型
  15. let columnArr = []; //列数组
  16. let moveTd = {}; //移动列
  17. let isNested = _targetDom.getElementsByTagName("table").length > 0;
  18. let setting = "setting-column";
  19. let settingInfo = localStorage.getItem("settingInfo") ? JSON.parse(localStorage.getItem("settingInfo")) : {
  20. isCopyWrap: true
  21. };
  22. let keyCode = false;
  23. let settingCheck = true;
  24. var beforeHeaderDom;
  25. var headerDom;
  26. function getTargetChildNode(dom) { //递归获取input子节点
  27. if (!dom || dom.tagName === 'INPUT') return dom;
  28. return getTargetChildNode(dom.firstElementChild);
  29. }
  30. function createHeaderBefore() {//生成前置元素
  31. let tr = document.createElement("tr");
  32. tr.className = "text-center";
  33. _before.forEach(be => {
  34. let th = document.createElement("th");
  35. if (be.colspan) th.colSpan = be.colspan;
  36. if (be.font) {
  37. let font = document.createElement("span");
  38. font.className = be.font;
  39. th.appendChild(font);
  40. }
  41. if (be.value) th.appendChild(document.createTextNode(be.value));
  42. if (be.class) th.className = be.class;
  43. tr.appendChild(th);
  44. });
  45. _targetDom.insertBefore(tr, _targetDom.firstElementChild);
  46. beforeHeaderDom = tr;
  47. }
  48. function appendFloat(div, cla = "") {
  49. div.style.overflowX = "hidden";
  50. div.className = "m-0 p-0";
  51. let th = document.createElement("th");
  52. th.className = "pl-2 pr-2 header-float " + cla;
  53. th.style.top = _fixedTop + "px";
  54. th.appendChild(div);
  55. return th;
  56. }
  57. function createHeader() {//生成表头列
  58. let tr = document.createElement("tr");
  59. tr.className = "text-nowrap";
  60. let firstTr = _targetDom.getElementsByTagName("tr")[0];
  61. let tds = [];
  62. if (firstTr) tds = firstTr.children;
  63. if (_isCheckAllBox) {//是否开启全选
  64. let div = document.createElement("div");
  65. let check = document.createElement("input");
  66. check.type = "checkbox";
  67. check.id = "checkAll";
  68. if (firstTr) bindCheckbox(check);
  69. div.appendChild(check);
  70. tr.appendChild(appendFloat(div, "text-left"));
  71. }
  72. let i = (_isCheckAllBox && firstTr) ? 1 : 0;
  73. for (i; i < (tds.length > 0 ? tds.length : _columns.length); i++) {
  74. let div = document.createElement("div");
  75. let th = appendFloat(div);
  76. let column = _columns[(_isCheckAllBox && firstTr) ? i - 1 : i];
  77. let wid = column ? localStorage.getItem(_name + column.name) : null;
  78. if (wid) {
  79. div.style.width = wid + "px";
  80. th.style.minWidth = wid + "px";
  81. let trs = _targetDom.children;
  82. while (trs[0] && trs[0].tagName !== 'TR') trs = trs[0].children;
  83. if (trs[0]) {
  84. for (let j = 0; j < trs.length; j++) {
  85. if (trs[j].children[i]) {
  86. trs[j].children[i].firstElementChild.style.width = wid + "px";
  87. trs[j].children[i].style.minWidth = wid + "px";
  88. }
  89. }
  90. }
  91. }
  92. if (column) {
  93. if (column.type === 'multi') multiColumn(div, column);
  94. else defaultColumn(div, column);
  95. }
  96. tr.appendChild(th);
  97. }
  98. bindMove(tr);
  99. if (_targetDom.firstElementChild) _targetDom.insertBefore(tr, _targetDom.firstElementChild);
  100. else _targetDom.appendChild(tr);
  101. headerDom = tr;
  102. }
  103. function multiColumn(th, column) { //多列样式的生成
  104. if (column.title) {
  105. let div = document.createElement("div");
  106. div.className = "w-100 text-center";
  107. div.appendChild(document.createTextNode(column.title));
  108. th.appendChild(div);
  109. }
  110. let div = document.createElement("div");
  111. div.className = "row text-center";
  112. if (column.rows) {
  113. column.rows.forEach(row => {
  114. let node = document.createElement("div");
  115. node.className = "col-" + (row.col ? row.col : 1);
  116. node.appendChild(document.createTextNode(row.value));
  117. div.appendChild(node);
  118. });
  119. th.appendChild(div);
  120. }
  121. }
  122. function defaultColumn(th, column) { //默认列样式的生成
  123. if (column.style) for (let key in column.style) if (column.style.hasOwnProperty(key)) th.parentElement.style[key] = column.style[key];
  124. if (column.class) th.parentElement.className += column.class;
  125. let span = document.createElement("span");
  126. span.style.display = "inline-block";
  127. if (!column.neglect) {
  128. span.style.cursor = "pointer";
  129. let font = document.createElement("span");
  130. font.className = "fa fa-sort";
  131. span.appendChild(font);
  132. span.onclick = rule(column, font); //绑定排序事件
  133. }
  134. span.appendChild(document.createTextNode((column.value ? column.value : '')));
  135. th.appendChild(span);
  136. }
  137. //点击事件触发的排序规则
  138. function rule(column, columnSort) {
  139. return function () {
  140. if (!sortType[column.name]) {
  141. sortType[column.name] = 'asc';
  142. columnArr.push(column.name);
  143. columnSort.className = "fa fa-sort-asc";
  144. let columnArrTemp = [];
  145. columnArrTemp.push.apply(columnArrTemp, columnArr);
  146. window.sort.sort(_data, columnArrTemp, sortType);
  147. return;
  148. }
  149. if (sortType[column.name] === 'asc') {
  150. sortType[column.name] = 'desc';
  151. columnSort.className = "fa fa-sort-desc";
  152. let columnArrTemp = [];
  153. columnArrTemp.push.apply(columnArrTemp, columnArr);
  154. window.sort.sort(_data, columnArrTemp, sortType);
  155. return;
  156. }
  157. if (sortType[column.name] === 'desc') {
  158. delete sortType[column.name];
  159. columnArr.some(function (name, index) {
  160. if (name === column.name) {
  161. columnArr.splice(index, 1);
  162. return true;
  163. }
  164. });
  165. columnSort.className = "fa fa-sort";
  166. if (columnArr.length === 0) {
  167. //希尔排序
  168. let arr = [];
  169. arr.push.apply(arr, _data);
  170. let len = arr.length;
  171. for (let gap = Math.floor(len / 2); gap > 0; gap = Math.floor(gap / 2)) {
  172. for (let i = gap; i < len; i++) {
  173. let j = i;
  174. let current = arr[i];
  175. if (_isRestorationColumnAsc) {
  176. while (j - gap >= 0 && Number(current[_restorationColumn]) < Number(arr[j - gap][_restorationColumn])) {
  177. arr[j] = arr[j - gap];
  178. j = j - gap;
  179. }
  180. } else {
  181. while (j - gap >= 0 && Number(current[_restorationColumn]) > Number(arr[j - gap][_restorationColumn])) {
  182. arr[j] = arr[j - gap];
  183. j = j - gap;
  184. }
  185. }
  186. arr[j] = current;
  187. }
  188. }
  189. _data.length = 0;
  190. _data.push.apply(_data, arr);
  191. return;
  192. }
  193. let columnArrTemp = [];
  194. columnArrTemp.push.apply(columnArrTemp, columnArr);
  195. window.sort.sort(_data, columnArrTemp, sortType);
  196. }
  197. }
  198. }
  199. function bindCheckbox(check) {
  200. let trs = _targetDom.children;
  201. while (trs[0].tagName !== 'TR') trs = trs[0].children;
  202. check.onchange = function () {
  203. if (event.target.checked) {
  204. for (let i = 0; i < trs.length; i++) {
  205. let checkbox = getTargetChildNode(trs[i].children[0]);
  206. if (checkbox && !checkbox.checked) {
  207. checkData.push(checkbox.value);
  208. checkbox.checked = true;
  209. }
  210. }
  211. } else {
  212. checkData = [];
  213. for (let i = 0; i < trs.length; i++) {
  214. let checkbox = getTargetChildNode(trs[i].children[0]);
  215. if (checkbox && checkbox.checked) checkbox.checked = false;
  216. }
  217. }
  218. };
  219. for (let i = 0; i < trs.length; i++) {
  220. let checkbox = getTargetChildNode(trs[i].children[0]);
  221. if (checkbox) checkbox.onchange = function () {
  222. if (event.target.checked) checkData.push(checkbox.value);
  223. else checkData.splice(checkData.indexOf(checkbox.value), 1);
  224. if (checkData.length === _data.length && !check.checked) check.checked = true;
  225. if (checkData.length !== _data.length && check.checked) check.checked = false;
  226. }
  227. }
  228. }
  229. function bindMove(tr) {
  230. if (_isForbidDrag) return;
  231. for (let j = 0; j < tr.children.length; j++) { //为首列绑定拖拽列宽事件
  232. tr.children[j].onmousedown = function () {
  233. if (j === 0 && event.offsetX < 10) return;
  234. if (event.offsetX < 10) moveTd = {oldX: event.clientX, dom: tr.children[j - 1], index: j - 1};
  235. if (event.offsetX > tr.children[j].offsetWidth - 10) moveTd = {
  236. oldX: event.clientX,
  237. dom: tr.children[j],
  238. index: j
  239. };
  240. };
  241. tr.children[j].onmousemove = function () {
  242. if (j === 0 && event.offsetX < 10) return;
  243. if (event.offsetX < 10 || event.offsetX > tr.children[j].offsetWidth - 10)
  244. this.style.cursor = 'w-resize';
  245. else this.style.cursor = 'default';
  246. }
  247. }
  248. document.onmouseup = function () { //全局监听拖拽列宽的发生 作用域设为全局是为了防抖动
  249. if (moveTd.oldX) {
  250. event.stopPropagation();
  251. moveTd.dom.style.cursor = 'default';
  252. moveTd.oldX = undefined;
  253. setTimeout(function () {
  254. let column = _columns[(_isCheckAllBox && _targetDom.firstElementChild) ? moveTd.index - 1 : moveTd.index];
  255. if (column) localStorage.setItem(_name + column.name, moveTd.dom.offsetWidth);
  256. });
  257. }
  258. }; //移动时调整表头与表身的列宽
  259. document.onmousemove = function () {
  260. if (moveTd.oldX) {
  261. event.stopPropagation();
  262. let diff = event.clientX - moveTd.oldX;
  263. let newWidth = moveTd.dom.firstElementChild.offsetWidth + diff + "px";
  264. if (diff !== 0) {
  265. let trs = _targetDom.getElementsByTagName("tr");
  266. for (let j = (_before ? 1 : 0); j < trs.length; j++) {
  267. if (isNested) {
  268. let table = trs[j].parentElement;
  269. while (table.tagName !== 'TABLE') table = table.parentElement;
  270. if (table.id !== object.el) continue;
  271. }
  272. if (trs[j].children[moveTd.index]) {
  273. trs[j].children[moveTd.index].firstElementChild.style.width = newWidth;
  274. trs[j].children[moveTd.index].style.minWidth = newWidth;
  275. }
  276. }
  277. _targetDom.style.width = _targetDom.offsetWidth + diff + "px";
  278. moveTd.oldX = event.clientX;
  279. }
  280. }
  281. };
  282. }
  283. function repaintDom() {
  284. let trs = _targetDom.getElementsByTagName("tr");
  285. for (let i = 0; i < trs.length; i++) {
  286. if (isNested) {
  287. let table = trs[i].parentElement;
  288. while (table.tagName !== 'TABLE') table = table.parentElement;
  289. if (table.id !== object.el) continue;
  290. }
  291. let tds = trs[i].children;
  292. for (let j = 0; j < tds.length; j++) {
  293. let count = tds[j].children.length;
  294. let div = document.createElement("div");
  295. div.style.overflowX = "hidden";
  296. for (let k = 0; k < count; k++) {
  297. div.appendChild(tds[j].children[0]);
  298. }
  299. tds[j].appendChild(div);
  300. tds[j].className += " pl-2 pr-2";
  301. }
  302. }
  303. }
  304. function showSetting(type) {
  305. return function () {
  306. let type2 = type === "setting-1" ? "setting-2" : "setting-1";
  307. document.getElementById(type2).style.display = "";
  308. document.getElementById(type).style.display = "none";
  309. };
  310. }
  311. function _createSetting1() {
  312. /*
  313. * <div id="setting-1" onclick="tt()" style="position: fixed;bottom: 0;left: 0;background-color: #1b1e21;width: 50px;height: 50px;cursor: pointer;text-align: center;border-radius: 3px">
  314. <h1><span class="fa fa-spin fa-gear" style="color: white;"></span></h1>
  315. </div>
  316. * */
  317. let div = document.createElement("div");
  318. div.id = "setting-1";
  319. div.style.position = "fixed";
  320. div.style.bottom = 0;
  321. div.style.left = 0;
  322. div.style.backgroundColor = "#1b1e21";
  323. div.style.width = "50px";
  324. div.style.height = "50px";
  325. div.style.cursor = "pointer";
  326. div.style.textAlign = "center";
  327. div.style.borderRadius = "3px";
  328. let h1 = document.createElement("h1");
  329. let span = document.createElement("span");
  330. span.className = "fa fa-gear";
  331. span.style.color = "white";
  332. div.onclick = showSetting("setting-1");
  333. h1.appendChild(span);
  334. div.appendChild(h1);
  335. document.body.appendChild(div);
  336. }
  337. function _createSettingHeader(text, id) {
  338. let div = document.createElement("div");
  339. div.style.width = "5%";
  340. div.style.display = "inline-block";
  341. div.style.borderLeft = "1px solid #aaaaaa";
  342. div.style.textAlign = "center";
  343. div.style.cursor = "pointer";
  344. div.innerText = text;
  345. div.id = id;
  346. div.onclick = function () {
  347. if (event.target.id === setting) return;
  348. let old = document.getElementById(setting);
  349. old.style.backgroundColor = "";
  350. old.style.color = "";
  351. document.getElementById(setting + "-body").style.display = "none";
  352. event.target.style.backgroundColor = "#3490dc";
  353. event.target.style.color = "white";
  354. document.getElementById(event.target.id + "-body").style.display = "";
  355. setting = event.target.id;
  356. };
  357. return div;
  358. }
  359. function bindColumnEvent() {
  360. return function () {
  361. let storage = localStorage.getItem("column:" + object.name);
  362. let arr = storage ? storage.split(',') : [];
  363. localStorage.setItem("column:" + object.name, _exeHid(arr).toString());
  364. };
  365. }
  366. function _exeHid(arr) {
  367. let nodes = document.getElementById("setting-column-body").getElementsByTagName("input");
  368. let show = [];
  369. let hid = [];
  370. let newArr = [];
  371. for (let i = 0; i < nodes.length; i++) {
  372. let value = nodes[i].value;
  373. let index = nodes[i].dataset.index;
  374. let checked = nodes[i].checked;
  375. if (checked && arr.indexOf(value) !== -1) show.push(index);
  376. if (!checked) {
  377. newArr.push(value);
  378. if (arr.indexOf(value) === -1) hid.push(index);
  379. }
  380. }
  381. let trs = _targetDom.getElementsByTagName("tr"); //所有行
  382. let total = trs[_before ? 1 : 0].children.length; //最大列
  383. for (let i = 0; i < trs.length; i++) {
  384. if (isNested) { //排除表格嵌套
  385. let table = trs[i].parentElement;
  386. while (table.tagName !== 'TABLE') table = table.parentElement;
  387. if (table.id !== object.el) continue;
  388. }
  389. if (total !== trs[i].children.length) { //存在合并行/列
  390. let pointer = [];//建立一个指针数组 用于存储下标指向真实element
  391. for (let j = 0; j < trs[i].children.length; j++) {
  392. if (trs[i].children[j] && trs[i].children[j].colSpan > 1) {
  393. for (let k = 0; k < trs[i].children[j].colSpan; k++) pointer.push(j);
  394. } else pointer.push(j);
  395. }
  396. for (let j = 0; j < show.length; j++) showOrHiddenDom(trs[i].children[pointer[show[j]]]);
  397. for (let j = 0; j < hid.length; j++) showOrHiddenDom(trs[i].children[pointer[hid[j]]], "hid");
  398. } else {
  399. for (let j = 0; j < show.length; j++) showOrHiddenDom(trs[i].children[show[j]]);
  400. for (let j = 0; j < hid.length; j++) showOrHiddenDom(trs[i].children[hid[j]], "hid");
  401. }
  402. }
  403. return newArr;
  404. }
  405. function showOrHiddenDom(dom, type = "show") {
  406. if (!dom) return;
  407. if (type === "show") {
  408. if (dom.colSpan > 1) dom.colSpan++;
  409. else dom.style.display = "";
  410. } else {
  411. if (dom.colSpan > 1) dom.colSpan--;
  412. else dom.style.display = "none";
  413. }
  414. }
  415. function appendCheckboxList(div) {
  416. let storage = localStorage.getItem("column:" + object.name);
  417. let arr = storage ? storage.split(',') : [];
  418. _columns.forEach(function (column, index) {
  419. let key = "setting-column-" + column.name;
  420. let label = document.createElement("label");
  421. label.style.float = "left";
  422. let input = document.createElement("input");
  423. input.type = "checkbox";
  424. input.id = key;
  425. input.className = "fixed-checkbox";
  426. input.dataset.index = _isCheckAllBox ? index + 1 : index;
  427. input.value = column.name;
  428. if (arr.indexOf(column.name) === -1) input.checked = true;
  429. label.appendChild(input);
  430. let la = document.createElement("label");
  431. la.setAttribute("for", key);
  432. label.appendChild(la);
  433. label.appendChild(document.createTextNode(column.type ? column.title : column.value));
  434. let prentLabel = document.createElement("label");
  435. prentLabel.style.width = "10%";
  436. prentLabel.appendChild(label);
  437. div.appendChild(prentLabel);
  438. });
  439. }
  440. function bindClearEvent(need) {
  441. return function () {
  442. for (let i = 0; i < localStorage.length; i++) {
  443. let key = localStorage.key(i);
  444. if (need === key.substring(0, need.length)) localStorage.removeItem(key);
  445. }
  446. };
  447. }
  448. function bindCheckAllEvent() {
  449. return function () {
  450. settingCheck = !settingCheck;
  451. let nodes = document.getElementById("setting-column-body").getElementsByTagName("input");
  452. for (let i = 0; i < nodes.length; i++) {
  453. if (nodes[i].checked !== settingCheck) nodes[i].checked = settingCheck;
  454. }
  455. }
  456. }
  457. function bindReverseEvent() {
  458. return function () {
  459. let nodes = document.getElementById("setting-column-body").getElementsByTagName("input");
  460. for (let i = 0; i < nodes.length; i++) nodes[i].checked = !nodes[i].checked;
  461. }
  462. }
  463. function _createSetting2() {
  464. /*
  465. * <div id="setting-2" style="background-color: white;position: fixed;bottom: 0;left: 0;width: 100%;display: none">
  466. <div style="width: 100%;background-color: RGB(245,245,200);border-top: 1px solid #1b1e21">
  467. <div style="width: 30px;display:inline-block;text-align: center"><span class="fa fa-gear w-100 h-100"></span></div>
  468. <div style="width: 5%;display:inline-block;border-left: 1px solid #aaaaaa;text-align: center;cursor: pointer;background-color: #3490dc;color: white">显示列</div>
  469. <div style="width: 5%;display:inline-block;border-left: 1px solid #aaaaaa;text-align: center;cursor: pointer">表头设置</div>
  470. <b style="float: right;margin-right:10px;cursor: pointer;font-size: 18px">&times;</b>
  471. </div>
  472. <div style="width: 100%;min-height: 50px;">
  473. <div style="margin: 10px 50px 20px 50px;width: 100%;" id="setting-data">
  474. <div id="setting-column">
  475. <label style="margin-right: 10px">
  476. 测试<input type="checkbox" id="column-x" class="fixed-checkbox" value="1" onclick="test()">
  477. <label for="column-x"></label>
  478. </label>
  479. <div>
  480. <button class="btn btn-sm btn-success">保存</button>
  481. </div>
  482. </div>
  483. <div id="setting-header">
  484. 清除本地列宽设置:
  485. <button type="button" class="btn btn-sm btn-outline-danger">清除全部</button>
  486. <button type="button" class="btn btn-sm btn-outline-danger">清除本页</button>
  487. </div>
  488. </div>
  489. </div>
  490. </div>
  491. * */
  492. let div = document.createElement("div");
  493. div.id = "setting-2";
  494. div.style.backgroundColor = "white";
  495. div.style.position = "fixed";
  496. div.style.bottom = 0;
  497. div.style.left = 0;
  498. div.style.width = "100%";
  499. div.style.display = "none";
  500. let div1 = document.createElement("div");
  501. div1.style.width = "100%";
  502. div1.style.backgroundColor = "RGB(245,245,220)";
  503. div1.style.borderTop = "1px solid #1b1e21";
  504. let div11 = document.createElement("div");
  505. div11.style.width = "30px";
  506. div11.style.display = "inline-block";
  507. div11.style.textAlign = "center";
  508. let span = document.createElement("span");
  509. span.className = "fa fa-gear";
  510. span.style.cursor = "pointer";
  511. span.onclick = showSetting("setting-2");
  512. div11.appendChild(span);
  513. div1.appendChild(div11);
  514. let div12 = _createSettingHeader("显示列", "setting-column");
  515. div12.style.backgroundColor = "#3490dc";
  516. div12.style.color = "white";
  517. div1.appendChild(div12);
  518. div1.appendChild(_createSettingHeader("表头设置", "setting-header"));
  519. let b = document.createElement("b");
  520. b.style.float = "right";
  521. b.style.marginRight = "10px";
  522. b.style.cursor = "pointer";
  523. b.style.fontSize = "18px";
  524. b.innerHTML = "&times;";
  525. b.onclick = showSetting("setting-2");
  526. div1.appendChild(b);
  527. div.appendChild(div1);
  528. //body
  529. let div2 = document.createElement("div");
  530. div2.style.width = "100%";
  531. div2.style.minHeight = "50px";
  532. div2.style.margin = "10px 50px 20px 50px";
  533. let div21 = document.createElement("div");
  534. div21.id = "setting-column-body";
  535. appendCheckboxList(div21);
  536. let btn = document.createElement("button");
  537. btn.className = "btn btn-sm btn-success";
  538. btn.type = "button";
  539. btn.innerText = "保存设置";
  540. btn.onclick = bindColumnEvent();
  541. let div211 = document.createElement("div");
  542. div211.appendChild(btn);
  543. let btn1 = document.createElement("button");
  544. btn1.className = "btn btn-sm btn-outline-info ml-1";
  545. btn1.type = "button";
  546. btn1.innerText = "全选/取消";
  547. btn1.onclick = bindCheckAllEvent();
  548. div211.appendChild(btn1);
  549. let btn2 = document.createElement("button");
  550. btn2.className = "btn btn-sm btn-outline-info ml-1";
  551. btn2.type = "button";
  552. btn2.innerText = "反选";
  553. btn2.onclick = bindReverseEvent();
  554. div211.appendChild(btn2);
  555. div21.appendChild(div211);
  556. div2.appendChild(div21);
  557. let div22 = document.createElement("div");
  558. div22.id = "setting-header-body";
  559. div22.style.display = "none";
  560. let div221 = document.createElement("div");
  561. div221.className = "row mt-2";
  562. let text = document.createElement("label");
  563. text.innerText = "清除本地列宽设置:";
  564. text.className = "text-right col-3";
  565. div221.appendChild(text);
  566. let btnA = document.createElement("button");
  567. btnA.className = "btn btn-sm btn-outline-danger";
  568. btnA.innerText = "清除全部";
  569. btnA.onclick = bindClearEvent("header:");
  570. div221.appendChild(btnA);
  571. let btnB = document.createElement("button");
  572. btnB.className = "ml-1 btn btn-sm btn-outline-danger";
  573. btnB.innerText = "清除本页";
  574. btnB.onclick = bindClearEvent(_name);
  575. div221.appendChild(btnB);
  576. let div222 = document.createElement("div");
  577. div222.className = "row mt-2";
  578. let text2 = document.createElement("label");
  579. text2.innerText = "禁止复制换行:";
  580. text2.className = "text-right col-3";
  581. div222.appendChild(text2);
  582. let input = document.createElement("input");
  583. input.type = "checkbox";
  584. input.className = "switch";
  585. input.checked = settingInfo.isCopyNoWrap;
  586. input.onchange = function () {
  587. settingInfo.isCopyNoWrap = event.target.checked;
  588. localStorage.setItem("settingInfo", JSON.stringify(settingInfo));
  589. };
  590. let div223 = document.createElement("div");
  591. div223.className = "row";
  592. let text3 = document.createElement("label");
  593. text3.innerText = "消息通知:";
  594. text3.className = "text-right col-3";
  595. div223.appendChild(text3);
  596. let btn3 = document.createElement("button");
  597. btn3.className = "btn btn-sm btn-outline-info";
  598. btn3.innerText = "打开消息面板";
  599. btn3.onclick = function () {
  600. let height = window.screen.height;
  601. window.open("https://" + window.location.host + "/notification/regular", 'newwindow', 'height=' + (height * 0.7) + ', width=510 ,top=' + (height * 0.10) +
  602. 'toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no');
  603. };
  604. div223.appendChild(btn3);
  605. div222.appendChild(input);
  606. div22.appendChild(div223);
  607. div22.appendChild(div221);
  608. div22.appendChild(div222);
  609. div2.appendChild(div22);
  610. div.appendChild(div2);
  611. document.body.appendChild(div);
  612. }
  613. function createSetting() {
  614. _createSetting1();
  615. _createSetting2();
  616. }
  617. function bindGlobalEvent() {
  618. document.onkeydown = (e) => {
  619. if (e.ctrlKey && e.keyCode === 67) keyCode = true;
  620. };
  621. document.oncopy = (e) => {
  622. if (keyCode && settingInfo.isCopyNoWrap) {
  623. e.preventDefault();
  624. let content = window.getSelection().toString();
  625. e.clipboardData.setData("text", content.replace(/[\n\r]/g, ' '));
  626. keyCode = false;
  627. }
  628. };
  629. }
  630. //初始化
  631. this.init = function () {
  632. if (!_isForbidDrag) repaintDom();
  633. createHeader();
  634. if (_before) createHeaderBefore();
  635. createSetting();
  636. _exeHid([]);
  637. bindGlobalEvent();
  638. _targetDom.style.width = _targetDom.offsetWidth + "px";
  639. };
  640. this.redrawHeader = function(column) {
  641. _columns = column;
  642. if (beforeHeaderDom) {
  643. _targetDom.removeChild(beforeHeaderDom);
  644. }
  645. if (headerDom) {
  646. _targetDom.removeChild(headerDom);
  647. }
  648. createHeader();
  649. if (_before) createHeaderBefore();
  650. }
  651. };