dataVerificationCtrl.js 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  1. import { replaceHtml } from '../utils/util';
  2. import formula from '../global/formula';
  3. import { isRealNum, isRealNull } from '../global/validate';
  4. import { isdatetime, diff } from '../global/datecontroll';
  5. import { luckysheetrefreshgrid } from '../global/refresh';
  6. import tooltip from '../global/tooltip';
  7. import { setcellvalue } from '../global/setdata';
  8. import { getcellvalue } from '../global/getdata';
  9. import editor from '../global/editor';
  10. import { modelHTML } from './constant';
  11. import { selectionCopyShow } from './select';
  12. import server from './server';
  13. import menuButton from './menuButton';
  14. import sheetmanage from './sheetmanage';
  15. import { getSheetIndex, getRangetxt } from '../methods/get';
  16. import locale from '../locale/locale';
  17. import Store from '../store';
  18. const dataVerificationCtrl = {
  19. defaultItem: {
  20. type: 'dropdown', //类型
  21. type2: null, //
  22. value1: '', //
  23. value2: '', //
  24. checked: false,
  25. remote: false, //自动远程获取选项
  26. prohibitInput: false, //输入数据无效时禁止输入
  27. hintShow: false, //选中单元格时显示提示语
  28. hintText: '', //
  29. },
  30. curItem: null,
  31. dataVerification: null,
  32. selectRange: [],
  33. selectStatus: false,
  34. optionLabel: {
  35. 'number': '数值',
  36. 'number_integer': '整数',
  37. 'number_decimal': '小数',
  38. 'bw': '介于',
  39. 'nb': '不介于',
  40. 'eq': '等于',
  41. 'ne': '不等于',
  42. 'gt': '大于',
  43. 'lt': '小于',
  44. 'gte': '大于等于',
  45. 'lte': '小于等于',
  46. 'include': '包括',
  47. 'exclude': '不包括',
  48. 'equal': '等于',
  49. 'bf': '早于',
  50. 'nbf': '不早于',
  51. 'af': '晚于',
  52. 'naf': '不晚于',
  53. 'card': '身份证号码',
  54. 'phone': '手机号'
  55. },
  56. optionLabel_en: {
  57. 'number': 'numeric',
  58. 'number_integer': 'integer',
  59. 'number_decimal': 'decimal',
  60. 'bw': 'between',
  61. 'nb': 'not between',
  62. 'eq': 'equal to',
  63. 'ne': 'not equal to',
  64. 'gt': 'greater',
  65. 'lt': 'less than',
  66. 'gte': 'greater or equal to',
  67. 'lte': 'less than or equal to',
  68. 'include': 'include',
  69. 'exclude': 'not include',
  70. 'equal': 'equal to',
  71. 'bf': 'earlier than',
  72. 'nbf': 'not earlier than',
  73. 'af': 'later than',
  74. 'naf': 'not later than',
  75. 'card': 'identification number',
  76. 'phone': 'phone number'
  77. },
  78. createDialog: function(){
  79. let _this = this;
  80. const _locale = locale();
  81. const dvText = _locale.dataVerification;
  82. const toolbarText = _locale.toolbar;
  83. const buttonText = _locale.button;
  84. $("#luckysheet-modal-dialog-mask").show();
  85. $("#luckysheet-dataVerification-dialog").remove();
  86. let content = `<div class="box">
  87. <div class="box-item" style="border-top:1px solid #E1E4E8;">
  88. <div class="box-item-title">${dvText.cellRange}</div>
  89. <div id="data-verification-range" class="range">
  90. <input class="formulaInputFocus" spellcheck="false">
  91. <i class="fa fa-table" aria-hidden="true" title="${dvText.selectCellRange}"></i>
  92. </div>
  93. </div>
  94. <div class="box-item">
  95. <div class="box-item-title">${dvText.verificationCondition}</div>
  96. <select id="data-verification-type-select">
  97. <option value="dropdown">${dvText.dropdown}</option>
  98. <option value="checkbox">${dvText.checkbox}</option>
  99. <option value="number">${dvText.number}</option>
  100. <option value="number_integer">${dvText.number_integer}</option>
  101. <option value="number_decimal">${dvText.number_decimal}</option>
  102. <option value="text_content">${dvText.text_content}</option>
  103. <option value="text_length">${dvText.text_length}</option>
  104. <option value="date">${dvText.date}</option>
  105. <option value="validity">${dvText.validity}</option>
  106. </select>
  107. <div class="show-box">
  108. <div class="show-box-item show-box-item-dropdown">
  109. <div class="range">
  110. <input class="formulaInputFocus data-verification-value1" placeholder="${dvText.placeholder1}" spellcheck="false">
  111. <i class="fa fa-table" aria-hidden="true" title="${dvText.selectCellRange}"></i>
  112. </div>
  113. <div class="multi">
  114. <input type="checkbox" id="data-verification-multi" class="data-verification-multi">
  115. <label for="data-verification-multi">${dvText.allowMultiSelect}</label>
  116. </div>
  117. </div>
  118. <div class="show-box-item show-box-item-checkbox">
  119. <div class="check-box">
  120. <span>${dvText.selected} ——</span>
  121. <input type="text" class="data-verification-value1" placeholder="${dvText.placeholder2}">
  122. </div>
  123. <div class="check-box">
  124. <span>${dvText.notSelected} ——</span>
  125. <input type="text" class="data-verification-value2" placeholder="${dvText.placeholder2}">
  126. </div>
  127. </div>
  128. <div class="show-box-item show-box-item-number">
  129. <select id="data-verification-number-select">
  130. <option value="bw">${dvText.between}</option>
  131. <option value="nb">${dvText.notBetween}</option>
  132. <option value="eq">${dvText.equal}</option>
  133. <option value="ne">${dvText.notEqualTo}</option>
  134. <option value="gt">${dvText.moreThanThe}</option>
  135. <option value="lt">${dvText.lessThan}</option>
  136. <option value="gte">${dvText.greaterOrEqualTo}</option>
  137. <option value="lte">${dvText.lessThanOrEqualTo}</option>
  138. </select>
  139. <div class="input input1">
  140. <input type="number" class="data-verification-value1" placeholder="1">
  141. <span>-</span>
  142. <input type="number" class="data-verification-value2" placeholder="100">
  143. </div>
  144. <div class="input input2">
  145. <input type="number" class="data-verification-value1" placeholder="${dvText.placeholder3}">
  146. </div>
  147. </div>
  148. <div class="show-box-item show-box-item-text">
  149. <select id="data-verification-text-select">
  150. <option value="include">${dvText.include}</option>
  151. <option value="exclude">${dvText.exclude}</option>
  152. <option value="equal">${dvText.equal}</option>
  153. </select>
  154. <div class="input input2">
  155. <input type="text" class="data-verification-value1" placeholder="${dvText.placeholder4}"/>
  156. </div>
  157. </div>
  158. <div class="show-box-item show-box-item-textLength">
  159. <select id="data-verification-textLength-select">
  160. <option value="bw">${dvText.between}</option>
  161. <option value="nb">${dvText.notBetween}</option>
  162. <option value="eq">${dvText.equal}</option>
  163. <option value="ne">${dvText.notEqualTo}</option>
  164. <option value="gt">${dvText.moreThanThe}</option>
  165. <option value="lt">${dvText.lessThan}</option>
  166. <option value="gte">${dvText.greaterOrEqualTo}</option>
  167. <option value="lte">${dvText.lessThanOrEqualTo}</option>
  168. </select>
  169. <div class="input input1">
  170. <input type="number" class="data-verification-value1" placeholder="1">
  171. <span>-</span>
  172. <input type="number" class="data-verification-value2" placeholder="100">
  173. </div>
  174. <div class="input input2">
  175. <input type="number" class="data-verification-value1" placeholder="${dvText.placeholder3}">
  176. </div>
  177. </div>
  178. <div class="show-box-item show-box-item-date">
  179. <select id="data-verification-date-select">
  180. <option value="bw">${dvText.between}</option>
  181. <option value="nb">${dvText.notBetween}</option>
  182. <option value="eq">${dvText.equal}</option>
  183. <option value="ne">${dvText.notEqualTo}</option>
  184. <option value="bf">${dvText.earlierThan}</option>
  185. <option value="nbf">${dvText.noEarlierThan}</option>
  186. <option value="af">${dvText.laterThan}</option>
  187. <option value="naf">${dvText.noLaterThan}</option>
  188. </select>
  189. <div class="input input1">
  190. <input type="date" class="data-verification-value1" placeholder="2020/9/10">
  191. <span>-</span>
  192. <input type="date" class="data-verification-value2" placeholder="2020/9/10">
  193. </div>
  194. <div class="input input2">
  195. <input type="date" class="data-verification-value1" placeholder="2020/9/10">
  196. </div>
  197. </div>
  198. <div class="show-box-item show-box-item-validity">
  199. <select id="data-verification-validity-select">
  200. <option value="card">${dvText.identificationNumber}</option>
  201. <option value="phone">${dvText.phoneNumber}</option>
  202. </select>
  203. </div>
  204. </div>
  205. </div>
  206. <div class="box-item">
  207. <div class="check">
  208. <input type="checkbox" id="data-verification-remote" class="data-verification-remote">
  209. <label for="data-verification-remote">${dvText.remote}</label>
  210. </div>
  211. <div class="check">
  212. <input type="checkbox" id="data-verification-prohibitInput">
  213. <label for="data-verification-prohibitInput">${dvText.prohibitInput}</label>
  214. </div>
  215. <div class="check">
  216. <input type="checkbox" id="data-verification-hint-show">
  217. <label for="data-verification-hint-show">${dvText.hintShow}</label>
  218. </div>
  219. <div class="data-verification-hint-text">
  220. <input type="text" placeholder="${dvText.placeholder5}">
  221. </div>
  222. </div>
  223. </div>`;
  224. $("body").first().append(replaceHtml(modelHTML, {
  225. "id": "luckysheet-dataVerification-dialog",
  226. "addclass": "luckysheet-dataVerification-dialog",
  227. "title": toolbarText.dataVerification,
  228. "content": content,
  229. "botton": `<button id="luckysheet-dataVerification-dialog-confirm" class="btn btn-primary">${buttonText.confirm}</button>
  230. <button id="luckysheet-dataVerification-dialog-delete" class="btn btn-default">${dvText.deleteVerification}</button>
  231. <button class="btn btn-default luckysheet-model-close-btn">${buttonText.cancel}</button>`,
  232. "style": "z-index:100003"
  233. }));
  234. let $t = $("#luckysheet-dataVerification-dialog").find(".luckysheet-modal-dialog-content").css("min-width", 350).end(),
  235. myh = $t.outerHeight(),
  236. myw = $t.outerWidth();
  237. let winw = $(window).width(),
  238. winh = $(window).height();
  239. let scrollLeft = $(document).scrollLeft(),
  240. scrollTop = $(document).scrollTop();
  241. $("#luckysheet-dataVerification-dialog").css({
  242. "left": (winw + scrollLeft - myw) / 2,
  243. "top": (winh + scrollTop - myh) / 3
  244. }).show();
  245. _this.dataAllocation();
  246. },
  247. init: function(){
  248. let _this = this;
  249. const dvText = locale().dataVerification;
  250. //单元格数据验证 类型是 下拉列表
  251. $(document).off("click.dropdownBtn").on("click.dropdownBtn", "#luckysheet-dataVerification-dropdown-btn", function(e) {
  252. _this.dropdownListShow();
  253. e.stopPropagation();
  254. });
  255. $(document).off("click.dropdownListItem").on("click.dropdownListItem", "#luckysheet-dataVerification-dropdown-List .dropdown-List-item", function(e) {
  256. var $item = $(this);
  257. let value = e.target.innerText;
  258. if ($item.hasClass('multi')) {
  259. $item.toggleClass('checked');
  260. value = $.map($("#luckysheet-dataVerification-dropdown-List").children().filter('.checked'), function(el) {
  261. return el.innerText;
  262. }).join(',');
  263. } else {
  264. $("#luckysheet-dataVerification-dropdown-List").hide();
  265. }
  266. let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
  267. let rowIndex = last.row_focus;
  268. let colIndex = last.column_focus;
  269. $("#luckysheet-rich-text-editor").text(value);
  270. formula.updatecell(rowIndex, colIndex);
  271. e.stopPropagation();
  272. });
  273. //单元格范围
  274. $(document).off("click.dvRange").on("click.dvRange", "#data-verification-range .fa-table", function(e) {
  275. $("#luckysheet-dataVerification-dialog").hide();
  276. let dataSource = "0";
  277. let txt = $(this).siblings("input").val().trim();
  278. _this.rangeDialog(dataSource, txt);
  279. _this.selectRange = [];
  280. let range = _this.getRangeByTxt(txt);
  281. formula.rangetosheet = Store.currentSheetIndex;
  282. if(range[0].sheetIndex != Store.currentSheetIndex){
  283. sheetmanage.changeSheetExec(range[0].sheetIndex);
  284. }
  285. if(range.length > 0){
  286. for(let s = 0; s < range.length; s++){
  287. let r1 = range[s].row[0], r2 = range[s].row[1];
  288. let c1 = range[s].column[0], c2 = range[s].column[1];
  289. let row = Store.visibledatarow[r2],
  290. row_pre = r1 - 1 == -1 ? 0 : Store.visibledatarow[r1 - 1];
  291. let col = Store.visibledatacolumn[c2],
  292. col_pre = c1 - 1 == -1 ? 0 : Store.visibledatacolumn[c1 - 1];
  293. _this.selectRange.push({
  294. "left": col_pre,
  295. "width": col - col_pre - 1,
  296. "top": row_pre,
  297. "height": row - row_pre - 1,
  298. "left_move": col_pre,
  299. "width_move": col - col_pre - 1,
  300. "top_move": row_pre,
  301. "height_move": row - row_pre - 1,
  302. "row": [r1, r2],
  303. "column": [c1, c2],
  304. "row_focus": r1,
  305. "column_focus": c1
  306. });
  307. }
  308. }
  309. selectionCopyShow(_this.selectRange);
  310. });
  311. $(document).off("click.dvRange2").on("click.dvRange2", "#luckysheet-dataVerification-dialog .show-box-item-dropdown .range .fa-table", function(e) {
  312. $("#luckysheet-dataVerification-dialog").hide();
  313. let dataSource = "1";
  314. let txt = $(this).siblings("input").val().trim();
  315. _this.rangeDialog(dataSource, txt);
  316. _this.selectRange = [];
  317. let range = _this.getRangeByTxt(txt);
  318. formula.rangetosheet = Store.currentSheetIndex;
  319. if(range[0].sheetIndex != Store.currentSheetIndex){
  320. sheetmanage.changeSheetExec(range[0].sheetIndex);
  321. }
  322. if(range.length > 0){
  323. for(let s = 0; s < range.length; s++){
  324. let r1 = range[s].row[0], r2 = range[s].row[1];
  325. let c1 = range[s].column[0], c2 = range[s].column[1];
  326. let row = Store.visibledatarow[r2],
  327. row_pre = r1 - 1 == -1 ? 0 : Store.visibledatarow[r1 - 1];
  328. let col = Store.visibledatacolumn[c2],
  329. col_pre = c1 - 1 == -1 ? 0 : Store.visibledatacolumn[c1 - 1];
  330. _this.selectRange.push({
  331. "left": col_pre,
  332. "width": col - col_pre - 1,
  333. "top": row_pre,
  334. "height": row - row_pre - 1,
  335. "left_move": col_pre,
  336. "width_move": col - col_pre - 1,
  337. "top_move": row_pre,
  338. "height_move": row - row_pre - 1,
  339. "row": [r1, r2],
  340. "column": [c1, c2],
  341. "row_focus": r1,
  342. "column_focus": c1
  343. });
  344. }
  345. }
  346. selectionCopyShow(_this.selectRange);
  347. });
  348. $(document).off("click.dvRangeConfirm").on("click.dvRangeConfirm", "#luckysheet-dataVerificationRange-dialog-confirm", function(e) {
  349. let dataSource = $(this).attr("data-source");
  350. let txt = $(this).parents("#luckysheet-dataVerificationRange-dialog").find("input").val();
  351. if(_this.getRangeByTxt(txt).length > 1){
  352. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', '不能对多重选择区域执行此操作,请选择单个区域,然后再试');
  353. return;
  354. }
  355. if(dataSource == '0'){
  356. $("#luckysheet-dataVerification-dialog #data-verification-range input").val(txt);
  357. }
  358. else if(dataSource == '1'){
  359. $("#luckysheet-dataVerification-dialog .show-box-item-dropdown .range input").val(txt);
  360. }
  361. $("#luckysheet-dataVerificationRange-dialog").hide();
  362. $("#luckysheet-modal-dialog-mask").show();
  363. $("#luckysheet-dataVerification-dialog").show();
  364. if(formula.rangetosheet != null && formula.rangetosheet != Store.currentSheetIndex){
  365. sheetmanage.changeSheetExec(formula.rangetosheet);
  366. formula.rangetosheet = null;
  367. }
  368. let range = [];
  369. selectionCopyShow(range);
  370. });
  371. $(document).off("click.dvRangeClose").on("click.dvRangeClose", "#luckysheet-dataVerificationRange-dialog-close", function(e) {
  372. $("#luckysheet-dataVerificationRange-dialog").hide();
  373. $("#luckysheet-modal-dialog-mask").show();
  374. $("#luckysheet-dataVerification-dialog").show();
  375. if(formula.rangetosheet != null && formula.rangetosheet != Store.currentSheetIndex){
  376. sheetmanage.changeSheetExec(formula.rangetosheet);
  377. formula.rangetosheet = null;
  378. }
  379. let range = [];
  380. selectionCopyShow(range);
  381. });
  382. $(document).on("click", "#luckysheet-dataVerificationRange-dialog .luckysheet-modal-dialog-title-close", function(e) {
  383. $("#luckysheet-dataVerificationRange-dialog").hide();
  384. $("#luckysheet-modal-dialog-mask").show();
  385. $("#luckysheet-dataVerification-dialog").show();
  386. if(formula.rangetosheet != null && formula.rangetosheet != Store.currentSheetIndex){
  387. sheetmanage.changeSheetExec(formula.rangetosheet);
  388. formula.rangetosheet = null;
  389. }
  390. let range = [];
  391. selectionCopyShow(range);
  392. })
  393. //验证条件 下拉框
  394. $(document).off("change.typeSelect").on("change.typeSelect", "#data-verification-type-select", function(e) {
  395. $("#luckysheet-dataVerification-dialog .show-box .show-box-item").hide();
  396. let value = this.value;
  397. let item = _this.curItem;
  398. if(value == 'dropdown'){
  399. $("#luckysheet-dataVerification-dialog .show-box .show-box-item-dropdown").show();
  400. let value1 = "";
  401. if(value == item.type){
  402. value1 = item.value1;
  403. }
  404. $("#luckysheet-dataVerification-dialog .show-box-item-dropdown .data-verification-value1").val(value1);
  405. $('#luckysheet-dataVerification-dialog #data-verification-multi').prop('checked', item.type2 ? true : false);
  406. }
  407. else if(value == 'checkbox'){
  408. $("#luckysheet-dataVerification-dialog .show-box .show-box-item-checkbox").show();
  409. let value1 = "";
  410. let value2 = "";
  411. if(value == item.type){
  412. value1 = item.value1;
  413. value2 = item.value2;
  414. }
  415. $("#luckysheet-dataVerification-dialog .show-box-item-checkbox .data-verification-value1").val(value1);
  416. $("#luckysheet-dataVerification-dialog .show-box-item-checkbox .data-verification-value2").val(value2);
  417. }
  418. else if(value == 'number' || value == 'number_integer' || value == 'number_decimal'){
  419. $("#luckysheet-dataVerification-dialog .show-box-item-number").show();
  420. $("#luckysheet-dataVerification-dialog .show-box-item-number .input").hide();
  421. let type2 = "bw";
  422. let value1 = "";
  423. let value2 = "";
  424. if(item.type == 'number' || item.type == 'number_integer' || item.type == 'number_decimal'){
  425. type2 = item.type2;
  426. value1 = item.value1;
  427. value2 = item.value2;
  428. }
  429. $("#luckysheet-dataVerification-dialog #data-verification-number-select").val(type2);
  430. if(type2 == 'bw' || type2 == 'nb'){
  431. $("#luckysheet-dataVerification-dialog .show-box-item-number .input1").show();
  432. }
  433. else{
  434. $("#luckysheet-dataVerification-dialog .show-box-item-number .input2").show();
  435. }
  436. $("#luckysheet-dataVerification-dialog .show-box-item-number .data-verification-value1").val(value1);
  437. $("#luckysheet-dataVerification-dialog .show-box-item-number .data-verification-value2").val(value2);
  438. }
  439. else if(value == 'text_content'){
  440. $("#luckysheet-dataVerification-dialog .show-box-item-text").show();
  441. let type2 = "include";
  442. let value1 = "";
  443. if(value == item.type){
  444. type2 = item.type2;
  445. value1 = item.value1;
  446. }
  447. $("#luckysheet-dataVerification-dialog #data-verification-text-select").val(type2);
  448. $("#luckysheet-dataVerification-dialog .show-box-item-text .data-verification-value1").val(value1);
  449. }
  450. else if(value == 'text_length'){
  451. $("#luckysheet-dataVerification-dialog .show-box-item-textLength").show();
  452. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input").hide();
  453. let type2 = "bw";
  454. let value1 = "";
  455. let value2 = "";
  456. if(value == item.type){
  457. type2 = item.type2;
  458. value1 = item.value1;
  459. value2 = item.value2;
  460. }
  461. $("#luckysheet-dataVerification-dialog #data-verification-textLength-select").val(type2);
  462. if(type2 == 'bw' || type2 == 'nb'){
  463. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input1").show();
  464. }
  465. else{
  466. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input2").show();
  467. }
  468. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .data-verification-value1").val(value1);
  469. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .data-verification-value2").val(value2);
  470. }
  471. else if(value == 'date'){
  472. $("#luckysheet-dataVerification-dialog .show-box-item-date").show();
  473. $("#luckysheet-dataVerification-dialog .show-box-item-date .input").hide();
  474. let type2 = "bw";
  475. let value1 = "";
  476. let value2 = "";
  477. if(value == item.type){
  478. type2 = item.type2;
  479. value1 = item.value1;
  480. value2 = item.value2;
  481. }
  482. $("#luckysheet-dataVerification-dialog #data-verification-date-select").val(type2);
  483. if(type2 == 'bw' || type2 == 'nb'){
  484. $("#luckysheet-dataVerification-dialog .show-box-item-date .input1").show();
  485. }
  486. else{
  487. $("#luckysheet-dataVerification-dialog .show-box-item-date .input2").show();
  488. }
  489. $("#luckysheet-dataVerification-dialog .show-box-item-date .data-verification-value1").val(value1);
  490. $("#luckysheet-dataVerification-dialog .show-box-item-date .data-verification-value2").val(value2);
  491. }
  492. else if(value == 'validity'){
  493. $("#luckysheet-dataVerification-dialog .show-box .show-box-item-validity").show();
  494. let type2 = "card";
  495. if(value == item.type){
  496. type2 = item.type2;
  497. }
  498. $("#luckysheet-dataVerification-dialog #data-verification-validity-select").val(type2);
  499. }
  500. });
  501. $(document).off("change.numberSelect").on("change.numberSelect", "#data-verification-number-select", function(e) {
  502. $("#luckysheet-dataVerification-dialog .show-box-item-number .input").hide();
  503. let value = this.value;
  504. if(value == 'bw' || value == 'nb'){
  505. $("#luckysheet-dataVerification-dialog .show-box-item-number .input1").show();
  506. }
  507. else{
  508. $("#luckysheet-dataVerification-dialog .show-box-item-number .input2").show();
  509. }
  510. });
  511. // 文本长度选择变化
  512. $(document).off("change.textLengthSelect").on("change.textLengthSelect", "#data-verification-textLength-select", function(e) {
  513. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input").hide();
  514. let value = this.value;
  515. if(value == 'bw' || value == 'nb'){
  516. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input1").show();
  517. }
  518. else{
  519. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input2").show();
  520. }
  521. });
  522. $(document).off("change.dateSelect").on("change.dateSelect", "#data-verification-date-select", function(e) {
  523. $("#luckysheet-dataVerification-dialog .show-box-item-date .input").hide();
  524. let value = this.value;
  525. if(value == 'bw' || value == 'nb'){
  526. $("#luckysheet-dataVerification-dialog .show-box-item-date .input1").show();
  527. }
  528. else{
  529. $("#luckysheet-dataVerification-dialog .show-box-item-date .input2").show();
  530. }
  531. });
  532. //选中单元格时显示提示语
  533. $(document).off("change.hintShow").on("change.hintShow", "#data-verification-hint-show", function(e) {
  534. if(this.checked){
  535. $("#luckysheet-dataVerification-dialog .data-verification-hint-text").show();
  536. }
  537. else{
  538. $("#luckysheet-dataVerification-dialog .data-verification-hint-text").hide();
  539. }
  540. });
  541. //确认按钮
  542. $(document).off("click.dvSaveConfirm").on("click.dvSaveConfirm", "#luckysheet-dataVerification-dialog-confirm", function(e) {
  543. let rangeTxt = $("#luckysheet-dataVerification-dialog #data-verification-range input").val().trim();
  544. let range = _this.getRangeByTxt(rangeTxt);
  545. if(range.length == 0){
  546. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.selectCellRange2);
  547. return;
  548. }
  549. let str = range[range.length - 1].row[0],
  550. edr = range[range.length - 1].row[1],
  551. stc = range[range.length - 1].column[0],
  552. edc = range[range.length - 1].column[1];
  553. let d = editor.deepCopyFlowData(Store.flowdata);
  554. if(str < 0){
  555. str = 0;
  556. }
  557. if(edr > d.length - 1){
  558. edr = d.length - 1;
  559. }
  560. if(stc < 0){
  561. stc = 0;
  562. }
  563. if(edc > d[0].length - 1){
  564. edc = d[0].length - 1;
  565. }
  566. let type = $("#luckysheet-dataVerification-dialog #data-verification-type-select").val();
  567. let type2 = null, value1 = "", value2 = "";
  568. if(type == 'dropdown'){
  569. value1 = $("#luckysheet-dataVerification-dialog .show-box-item-dropdown .data-verification-value1").val().trim();
  570. if(value1.length == 0){
  571. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo1);
  572. return;
  573. }
  574. type2 = $("#luckysheet-dataVerification-dialog #data-verification-multi").is(':checked');
  575. }
  576. else if(type == 'checkbox'){
  577. value1 = $("#luckysheet-dataVerification-dialog .show-box-item-checkbox .data-verification-value1").val().trim();
  578. value2 = $("#luckysheet-dataVerification-dialog .show-box-item-checkbox .data-verification-value2").val().trim();
  579. if(value1.length == 0 || value2.length == 0){
  580. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo2);
  581. return;
  582. }
  583. }
  584. else if(type == 'number' || type == 'number_integer' || type == 'number_decimal'){
  585. type2 = $("#luckysheet-dataVerification-dialog #data-verification-number-select").val();
  586. value1 = $("#luckysheet-dataVerification-dialog .show-box-item-number .input:visible .data-verification-value1").val().trim();
  587. if(!isRealNum(value1)){
  588. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo3);
  589. return;
  590. }
  591. if(type2 == 'bw' || type2 == 'nb'){
  592. value2 = $("#luckysheet-dataVerification-dialog .show-box-item-number .input:visible .data-verification-value2").val().trim();
  593. if(!isRealNum(value2)){
  594. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo3);
  595. return;
  596. }
  597. if(Number(value2) < Number(value1)){
  598. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo4);
  599. return;
  600. }
  601. }
  602. }
  603. else if(type == 'text_content'){
  604. type2 = $("#luckysheet-dataVerification-dialog #data-verification-text-select").val();
  605. value1 = $("#luckysheet-dataVerification-dialog .show-box-item-text .data-verification-value1").val().trim();
  606. if(value1.length == 0){
  607. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo5);
  608. return;
  609. }
  610. }
  611. else if(type == 'text_length'){
  612. type2 = $("#luckysheet-dataVerification-dialog #data-verification-textLength-select").val();
  613. value1 = $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input:visible .data-verification-value1").val().trim();
  614. if(!isRealNum(value1)){
  615. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo3);
  616. return;
  617. }
  618. if (!Number.isInteger(Number(value1)) || Number(value1) < 0) {
  619. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.textlengthInteger);
  620. return;
  621. }
  622. if(type2 == 'bw' || type2 == 'nb'){
  623. value2 = $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input:visible .data-verification-value2").val().trim();
  624. if(!isRealNum(value2)){
  625. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo3);
  626. return;
  627. }
  628. if (!Number.isInteger(Number(value2)) || Number(value2) < 0) {
  629. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.textlengthInteger);
  630. return;
  631. }
  632. if(Number(value2) < Number(value1)){
  633. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo4);
  634. return;
  635. }
  636. }
  637. }
  638. else if(type == 'date'){
  639. type2 = $("#luckysheet-dataVerification-dialog #data-verification-date-select").val();
  640. value1 = $("#luckysheet-dataVerification-dialog .show-box-item-date .input:visible .data-verification-value1").val().trim();
  641. if(!isdatetime(value1)){
  642. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo6);
  643. return;
  644. }
  645. if(type2 == 'bw' || type2 == 'nb'){
  646. value2 = $("#luckysheet-dataVerification-dialog .show-box-item-date .input:visible .data-verification-value2").val().trim();
  647. if(!isdatetime(value2)){
  648. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo6);
  649. return;
  650. }
  651. if(diff(value1, value2) > 0){
  652. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.tooltipInfo7);
  653. return;
  654. }
  655. }
  656. }
  657. else if(type == 'validity'){
  658. type2 = $("#luckysheet-dataVerification-dialog #data-verification-validity-select").val();
  659. }
  660. let remote = $("#luckysheet-dataVerification-dialog #data-verification-remote").is(":checked");
  661. let prohibitInput = $("#luckysheet-dataVerification-dialog #data-verification-prohibitInput").is(":checked");
  662. let hintShow = $("#luckysheet-dataVerification-dialog #data-verification-hint-show").is(":checked");
  663. let hintText = "";
  664. if(hintShow){
  665. hintText = $("#luckysheet-dataVerification-dialog .data-verification-hint-text input").val().trim();
  666. }
  667. let item = {
  668. type: type,
  669. type2: type2,
  670. value1: value1,
  671. value2: value2,
  672. checked: false,
  673. remote: remote,
  674. prohibitInput: prohibitInput,
  675. hintShow: hintShow,
  676. hintText: hintText,
  677. }
  678. let historyDataVerification = $.extend(true, {}, _this.dataVerification);
  679. let currentDataVerification = $.extend(true, {}, _this.dataVerification);
  680. for(let r = str; r <= edr; r++){
  681. for(let c = stc; c <= edc; c++){
  682. currentDataVerification[r + '_' + c] = item;
  683. if(type == 'checkbox'){
  684. setcellvalue(r, c, d, item.value2);
  685. }
  686. }
  687. }
  688. if(type == 'checkbox'){
  689. _this.refOfCheckbox(historyDataVerification, currentDataVerification, Store.currentSheetIndex, d, range[range.length - 1]);
  690. }
  691. else{
  692. _this.ref(historyDataVerification, currentDataVerification, Store.currentSheetIndex);
  693. }
  694. $("#luckysheet-modal-dialog-mask").hide();
  695. $("#luckysheet-dataVerification-dialog").hide();
  696. });
  697. //删除验证按钮
  698. $(document).off("click.delete").on("click.delete", "#luckysheet-dataVerification-dialog-delete", function(e) {
  699. let rangeTxt = $("#luckysheet-dataVerification-dialog #data-verification-range input").val().trim();
  700. let range = _this.getRangeByTxt(rangeTxt);
  701. if(range.length == 0){
  702. tooltip.info('<i class="fa fa-exclamation-triangle"></i>', dvText.selectCellRange2);
  703. return;
  704. }
  705. let historyDataVerification = $.extend(true, {}, _this.dataVerification);
  706. let currentDataVerification = $.extend(true, {}, _this.dataVerification);
  707. let str = range[range.length - 1].row[0],
  708. edr = range[range.length - 1].row[1],
  709. stc = range[range.length - 1].column[0],
  710. edc = range[range.length - 1].column[1];
  711. for(let r = str; r <= edr; r++){
  712. for(let c = stc; c <= edc; c++){
  713. delete currentDataVerification[r + '_' + c];
  714. }
  715. }
  716. _this.ref(historyDataVerification, currentDataVerification, Store.currentSheetIndex);
  717. $("#luckysheet-modal-dialog-mask").hide();
  718. $("#luckysheet-dataVerification-dialog").hide();
  719. });
  720. //info提示弹框 关闭
  721. $(document).on("click", "#luckysheet-info .luckysheet-modal-dialog-title-close, #luckysheet-info .luckysheet-model-close-btn", function(e) {
  722. $(this).parents("#luckysheet-info").hide();
  723. if($("#luckysheet-dataVerification-dialog").is(":visible")){
  724. $("#luckysheet-modal-dialog-mask").show();
  725. }
  726. e.stopPropagation();
  727. });
  728. },
  729. dataAllocation: function(){
  730. let _this = this;
  731. //单元格范围
  732. let range = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
  733. let rangeTxt = getRangetxt(Store.currentSheetIndex, range, Store.currentSheetIndex);
  734. $("#luckysheet-dataVerification-dialog #data-verification-range input").val(rangeTxt);
  735. //focus单元格
  736. let rowIndex = range.row_focus || range.row[0];
  737. let colIndex = range.column_focus || range.column[0];
  738. let dataVerification = $.extend(true, {}, _this.dataVerification);
  739. let item = dataVerification[rowIndex + '_' + colIndex];
  740. if(item == null){
  741. item = $.extend(true, {}, _this.defaultItem);
  742. }
  743. _this.curItem = item;
  744. //验证条件
  745. $("#luckysheet-dataVerification-dialog #data-verification-type-select").val(item.type);
  746. $("#luckysheet-dataVerification-dialog .show-box .show-box-item").hide();
  747. if(item.type == 'dropdown'){
  748. $("#luckysheet-dataVerification-dialog .show-box .show-box-item-dropdown").show();
  749. $("#luckysheet-dataVerification-dialog .show-box-item-dropdown .data-verification-value1").val(item.value1);
  750. $('#luckysheet-dataVerification-dialog #data-verification-multi').prop('checked', item.type2 ? true : false);
  751. }
  752. else if(item.type == 'checkbox'){
  753. $("#luckysheet-dataVerification-dialog .show-box .show-box-item-checkbox").show();
  754. $("#luckysheet-dataVerification-dialog .show-box-item-checkbox .data-verification-value1").val(item.value1);
  755. $("#luckysheet-dataVerification-dialog .show-box-item-checkbox .data-verification-value2").val(item.value2);
  756. }
  757. else if(item.type == 'number' || item.type == 'number_integer' || item.type == 'number_decimal'){
  758. $("#luckysheet-dataVerification-dialog .show-box-item-number").show();
  759. $("#luckysheet-dataVerification-dialog #data-verification-number-select").val(item.type2);
  760. $("#luckysheet-dataVerification-dialog .show-box-item-number .input").hide();
  761. if(item.type2 == 'bw' || item.type2 == 'nb'){
  762. $("#luckysheet-dataVerification-dialog .show-box-item-number .input1").show();
  763. }
  764. else{
  765. $("#luckysheet-dataVerification-dialog .show-box-item-number .input2").show();
  766. }
  767. $("#luckysheet-dataVerification-dialog .show-box-item-number .data-verification-value1").val(item.value1);
  768. $("#luckysheet-dataVerification-dialog .show-box-item-number .data-verification-value2").val(item.value2);
  769. }
  770. else if(item.type == 'text_content'){
  771. $("#luckysheet-dataVerification-dialog .show-box-item-text").show();
  772. $("#luckysheet-dataVerification-dialog #data-verification-text-select").val(item.type2);
  773. $("#luckysheet-dataVerification-dialog .show-box-item-text .data-verification-value1").val(item.value1);
  774. }
  775. else if(item.type == 'text_length'){
  776. $("#luckysheet-dataVerification-dialog .show-box-item-textLength").show();
  777. $("#luckysheet-dataVerification-dialog #data-verification-textLength-select").val(item.type2);
  778. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input").hide();
  779. if(item.type2 == 'bw' || item.type2 == 'nb'){
  780. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input1").show();
  781. }
  782. else{
  783. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input2").show();
  784. }
  785. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .data-verification-value1").val(item.value1);
  786. $("#luckysheet-dataVerification-dialog .show-box-item-textLength .data-verification-value2").val(item.value2);
  787. }
  788. else if(item.type == 'date'){
  789. $("#luckysheet-dataVerification-dialog .show-box-item-date").show();
  790. $("#luckysheet-dataVerification-dialog #data-verification-date-select").val(item.type2);
  791. $("#luckysheet-dataVerification-dialog .show-box-item-date .input").hide();
  792. if(item.type2 == 'bw' || item.type2 == 'nb'){
  793. $("#luckysheet-dataVerification-dialog .show-box-item-date .input1").show();
  794. }
  795. else{
  796. $("#luckysheet-dataVerification-dialog .show-box-item-date .input2").show();
  797. }
  798. $("#luckysheet-dataVerification-dialog .show-box-item-date .data-verification-value1").val(item.value1);
  799. $("#luckysheet-dataVerification-dialog .show-box-item-date .data-verification-value2").val(item.value2);
  800. }
  801. else if(item.type == 'validity'){
  802. $("#luckysheet-dataVerification-dialog .show-box .show-box-item-validity").show();
  803. $("#luckysheet-dataVerification-dialog #data-verification-validity-select").val(item.type2);
  804. }
  805. //自动远程获取选项
  806. $("#luckysheet-dataVerification-dialog #data-verification-remote").prop("checked", item.remote);
  807. //输入数据无效时禁止输入
  808. $("#luckysheet-dataVerification-dialog #data-verification-prohibitInput").prop("checked", item.prohibitInput);
  809. //选中单元格时显示提示语
  810. $("#luckysheet-dataVerification-dialog #data-verification-hint-show").prop("checked", item.hintShow);
  811. if(item.hintShow){
  812. $("#luckysheet-dataVerification-dialog .data-verification-hint-text").show();
  813. }
  814. else{
  815. $("#luckysheet-dataVerification-dialog .data-verification-hint-text").hide();
  816. }
  817. $("#luckysheet-dataVerification-dialog .data-verification-hint-text input").val(item.hintText);
  818. },
  819. rangeDialog: function(dataSource, txt){
  820. let _this = this;
  821. const _locale = locale();
  822. const dvText = _locale.dataVerification;
  823. const buttonText = _locale.button;
  824. $("#luckysheet-modal-dialog-mask").hide();
  825. $("#luckysheet-dataVerificationRange-dialog").remove();
  826. $("body").first().append(replaceHtml(modelHTML, {
  827. "id": "luckysheet-dataVerificationRange-dialog",
  828. "addclass": "luckysheet-dataVerificationRange-dialog",
  829. "title": dvText.selectCellRange,
  830. "content": `<input readonly="readonly" placeholder="${dvText.selectCellRange2}" value="${txt}"/>`,
  831. "botton": `<button id="luckysheet-dataVerificationRange-dialog-confirm" class="btn btn-primary" data-source="${dataSource}">${buttonText.confirm}</button>
  832. <button id="luckysheet-dataVerificationRange-dialog-close" class="btn btn-default">${buttonText.close}</button>`,
  833. "style": "z-index:100003"
  834. }));
  835. let $t = $("#luckysheet-dataVerificationRange-dialog")
  836. .find(".luckysheet-modal-dialog-content")
  837. .css("min-width", 300)
  838. .end(),
  839. myh = $t.outerHeight(),
  840. myw = $t.outerWidth();
  841. let winw = $(window).width(), winh = $(window).height();
  842. let scrollLeft = $(document).scrollLeft(), scrollTop = $(document).scrollTop();
  843. $("#luckysheet-dataVerificationRange-dialog").css({
  844. "left": (winw + scrollLeft - myw) / 2,
  845. "top": (winh + scrollTop - myh) / 3
  846. }).show();
  847. },
  848. getTxtByRange: function(range){
  849. if(range.length > 0){
  850. let txt = [];
  851. for(let s = 0; s < range.length; s++){
  852. let r1 = range[s].row[0], r2 = range[s].row[1];
  853. let c1 = range[s].column[0], c2 = range[s].column[1];
  854. txt.push(getRangetxt(Store.currentSheetIndex, { "row": [r1, r2], "column": [c1, c2] }, Store.currentSheetIndex));
  855. }
  856. return txt.join(",");
  857. }
  858. },
  859. getRangeByTxt: function(txt){
  860. let range = [];
  861. if(txt.indexOf(",") != -1){
  862. let arr = txt.split(",");
  863. for(let i = 0; i < arr.length; i++){
  864. if(formula.iscelldata(arr[i])){
  865. range.push(formula.getcellrange(arr[i]));
  866. }
  867. else{
  868. range = [];
  869. break;
  870. }
  871. }
  872. }
  873. else{
  874. if(formula.iscelldata(txt)){
  875. range.push(formula.getcellrange(txt));
  876. }
  877. }
  878. return range;
  879. },
  880. cellFocus: function(r, c, clickMode){
  881. $("#luckysheet-dataVerification-dropdown-btn").hide();
  882. $("#luckysheet-dataVerification-showHintBox").hide();
  883. let _this = this;
  884. if(_this.dataVerification == null || _this.dataVerification[r + '_' + c] == null){
  885. $("#luckysheet-dataVerification-dropdown-List").hide();
  886. return;
  887. }
  888. let row = Store.visibledatarow[r],
  889. row_pre = r == 0 ? 0 : Store.visibledatarow[r - 1];
  890. let col = Store.visibledatacolumn[c],
  891. col_pre = c == 0 ? 0 : Store.visibledatacolumn[c - 1];
  892. let margeset = menuButton.mergeborer(Store.flowdata, r, c);
  893. if(!!margeset){
  894. row = margeset.row[1];
  895. row_pre = margeset.row[0];
  896. col = margeset.column[1];
  897. col_pre = margeset.column[0];
  898. }
  899. let item = _this.dataVerification[r + '_' + c];
  900. //单元格数据验证 类型是 复选框
  901. if(clickMode && item.type == 'checkbox'){
  902. _this.checkboxChange(r, c);
  903. return;
  904. }
  905. //单元格数据验证 类型是 下拉列表
  906. if(item.type == 'dropdown'){
  907. $("#luckysheet-dataVerification-dropdown-btn").show().css({
  908. 'max-width': col - col_pre,
  909. 'max-height': row - row_pre,
  910. 'left': col - 20,
  911. 'top': row_pre + (row - row_pre - 20) / 2
  912. })
  913. if($("#luckysheet-dataVerification-dropdown-List").is(":visible")){
  914. let dataIndex = $("#luckysheet-dataVerification-dropdown-List").prop("data-index");
  915. if(dataIndex != (r + '_' + c)){
  916. $("#luckysheet-dataVerification-dropdown-List").hide();
  917. }
  918. }
  919. }
  920. else{
  921. $("#luckysheet-dataVerification-dropdown-List").hide();
  922. }
  923. //提示语
  924. if(item.hintShow){
  925. let hintText;
  926. if(Store.lang == 'en'){
  927. hintText = '<span style="color:#f5a623;">Hint: </span>';
  928. }
  929. else{
  930. hintText = '<span style="color:#f5a623;">提示:</span>';
  931. }
  932. hintText += _this.getHintText(item);
  933. $("#luckysheet-dataVerification-showHintBox").html(hintText).show().css({
  934. 'left': col_pre,
  935. 'top': row
  936. });
  937. return;
  938. }
  939. //数据验证未通过
  940. let cellValue = getcellvalue(r, c, null);
  941. if(isRealNull(cellValue)){
  942. return;
  943. }
  944. let validate = _this.validateCellData(cellValue, item);
  945. if(!validate){
  946. let failureText;
  947. if(Store.lang == 'en'){
  948. failureText = '<span style="color:#f72626;">Failure: </span>';
  949. }
  950. else{
  951. failureText = '<span style="color:#f72626;">失效:</span>';
  952. }
  953. failureText += _this.getFailureText(item);
  954. $("#luckysheet-dataVerification-showHintBox").html(failureText).show().css({
  955. 'left': col_pre,
  956. 'top': row
  957. });
  958. }
  959. },
  960. getHintText: function(item) {
  961. let _this = this;
  962. let hintText = item.hintText || '';
  963. if(hintText.length == 0){
  964. if(Store.lang == 'en'){
  965. if(item.type == 'dropdown'){
  966. hintText += 'please select an option in the drop-down list';
  967. }
  968. else if(item.type == 'checkbox'){
  969. }
  970. else if(item.type == 'number' || item.type == 'number_integer' || item.type == 'number_decimal'){
  971. hintText += 'please enter a ' + _this.optionLabel_en[item.type] + ' ' + _this.optionLabel_en[item.type2] + ' ' + item.value1;
  972. if(item.type2 == 'bw' || item.type2 == 'nb'){
  973. hintText += ' and ' + item.value2;
  974. }
  975. }
  976. else if(item.type == 'text_content'){
  977. hintText += 'please enter text ' + _this.optionLabel_en[item.type2] + ' ' + item.value1;
  978. }
  979. else if(item.type == 'text_length'){
  980. hintText += 'please enter text with length ' + _this.optionLabel_en[item.type2] + ' ' + item.value1;
  981. if(item.type2 == 'bw' || item.type2 == 'nb'){
  982. hintText += ' and ' + item.value2;
  983. }
  984. }
  985. else if(item.type == 'date'){
  986. hintText += 'please enter a date ' + _this.optionLabel_en[item.type2] + ' ' + item.value1;
  987. if(item.type2 == 'bw' || item.type2 == 'nb'){
  988. hintText += ' and ' + item.value2;
  989. }
  990. }
  991. else if(item.type == 'validity'){
  992. hintText += 'please enter the correct ' + _this.optionLabel_en[item.type2];
  993. }
  994. }
  995. else{
  996. if(item.type == 'dropdown'){
  997. hintText += '请选择下拉列表中的选项';
  998. }
  999. else if(item.type == 'checkbox'){
  1000. }
  1001. else if(item.type == 'number' || item.type == 'number_integer' || item.type == 'number_decimal'){
  1002. hintText += '请输入' + _this.optionLabel[item.type2] + item.value1;
  1003. if(item.type2 == 'bw' || item.type2 == 'nb'){
  1004. hintText += '和' + item.value2 + '之间';
  1005. }
  1006. hintText += '的' + _this.optionLabel[item.type];
  1007. }
  1008. else if(item.type == 'text_content'){
  1009. hintText += '请输入内容' + _this.optionLabel[item.type2] + item.value1 + '的文本';
  1010. }
  1011. else if(item.type == 'text_length'){
  1012. hintText += '请输入长度' + _this.optionLabel[item.type2] + item.value1;
  1013. if(item.type2 == 'bw' || item.type2 == 'nb'){
  1014. hintText += '和' + item.value2 + '之间';
  1015. }
  1016. hintText += '的文本';
  1017. }
  1018. else if(item.type == 'date'){
  1019. hintText += '请输入' + _this.optionLabel[item.type2] + item.value1;
  1020. if(item.type2 == 'bw' || item.type2 == 'nb'){
  1021. hintText += '和' + item.value2 + '之间';
  1022. }
  1023. hintText += '的日期';
  1024. }
  1025. else if(item.type == 'validity'){
  1026. hintText += '请输入正确的' + _this.optionLabel[item.type2];
  1027. }
  1028. }
  1029. }
  1030. return hintText;
  1031. },
  1032. getFailureText: function(item) {
  1033. let _this = this;
  1034. let failureText = '';
  1035. if(Store.lang == 'en'){
  1036. if(item.type == 'dropdown'){
  1037. failureText += 'what you selected is not an option in the drop-down list';
  1038. }
  1039. else if(item.type == 'checkbox'){
  1040. }
  1041. else if(item.type == 'number' || item.type == 'number_integer' || item.type == 'number_decimal'){
  1042. failureText += 'what you entered is not a ' + _this.optionLabel_en[item.type] + ' ' + _this.optionLabel_en[item.type2] + ' ' + item.value1;
  1043. if(item.type2 == 'bw' || item.type2 == 'nb'){
  1044. failureText += ' and ' + item.value2;
  1045. }
  1046. }
  1047. else if(item.type == 'text_content'){
  1048. failureText += 'what you entered is not text that ' + _this.optionLabel_en[item.type2] + ' ' + item.value1;
  1049. }
  1050. else if(item.type == 'text_length'){
  1051. failureText += 'the text you entered is not length ' + _this.optionLabel_en[item.type2] + ' ' + item.value1;
  1052. if(item.type2 == 'bw' || item.type2 == 'nb'){
  1053. failureText += ' and ' + item.value2;
  1054. }
  1055. }
  1056. else if(item.type == 'date'){
  1057. failureText += 'the date you entered is not ' + _this.optionLabel_en[item.type2] + ' ' + item.value1;
  1058. if(item.type2 == 'bw' || item.type2 == 'nb'){
  1059. failureText += ' and ' + item.value2;
  1060. }
  1061. }
  1062. else if(item.type == 'validity'){
  1063. failureText += 'what you entered is not a correct ' + _this.optionLabel_en[item.type2];
  1064. }
  1065. }
  1066. else{
  1067. if(item.type == 'dropdown'){
  1068. failureText += '你选择的不是下拉列表中的选项';
  1069. }
  1070. else if(item.type == 'checkbox'){
  1071. }
  1072. else if(item.type == 'number' || item.type == 'number_integer' || item.type == 'number_decimal'){
  1073. failureText += '你输入的不是' + _this.optionLabel[item.type2] + item.value1;
  1074. if(item.type2 == 'bw' || item.type2 == 'nb'){
  1075. failureText += '和' + item.value2 + '之间';
  1076. }
  1077. failureText += '的' + _this.optionLabel[item.type];
  1078. }
  1079. else if(item.type == 'text_content'){
  1080. failureText += '你输入的不是内容' + _this.optionLabel[item.type2] + item.value1 + '的文本';
  1081. }
  1082. else if(item.type == 'text_length'){
  1083. failureText += '你输入的不是长度' + _this.optionLabel[item.type2] + item.value1;
  1084. if(item.type2 == 'bw' || item.type2 == 'nb'){
  1085. failureText += '和' + item.value2 + '之间';
  1086. }
  1087. failureText += '的文本';
  1088. }
  1089. else if(item.type == 'date'){
  1090. failureText += '你输入的不是' + _this.optionLabel[item.type2] + item.value1;
  1091. if(item.type2 == 'bw' || item.type2 == 'nb'){
  1092. failureText += '和' + item.value2 + '之间';
  1093. }
  1094. failureText += '的日期';
  1095. }
  1096. else if(item.type == 'validity'){
  1097. failureText += '你输入的不是一个正确的' + _this.optionLabel[item.type2];
  1098. }
  1099. }
  1100. return failureText;
  1101. },
  1102. validateCellData: function(cellValue, item){
  1103. let _this = this;
  1104. let type = item.type,
  1105. type2 = item.type2,
  1106. value1 = item.value1,
  1107. value2 = item.value2;
  1108. if(type == 'dropdown'){
  1109. let list = _this.getDropdownList(value1);
  1110. // 多选的情况 检查每个都在下拉列表中
  1111. if(type2 && cellValue){
  1112. return cellValue.split(',').every(function (i) {
  1113. return list.indexOf(i) !== -1;
  1114. });
  1115. }
  1116. let result = false;
  1117. for(let i = 0; i < list.length; i++){
  1118. if(list[i] == cellValue){
  1119. result = true;
  1120. break;
  1121. }
  1122. }
  1123. return result;
  1124. }
  1125. else if(type == 'checkbox'){
  1126. }
  1127. else if(type == 'number' || type == 'number_integer' || type == 'number_decimal'){
  1128. if(!isRealNum(cellValue)){
  1129. return false;
  1130. }
  1131. cellValue = Number(cellValue);
  1132. if(type == 'number_integer' && cellValue % 1 !== 0){
  1133. return false;
  1134. }
  1135. if(type == 'number_decimal' && cellValue % 1 === 0){
  1136. return false;
  1137. }
  1138. value1 = Number(value1);
  1139. value2 = Number(value2);
  1140. if(type2 == 'bw' && (cellValue < value1 || cellValue > value2)){
  1141. return false;
  1142. }
  1143. if(type2 == 'nb' && (cellValue >= value1 && cellValue <= value2)){
  1144. return false;
  1145. }
  1146. if(type2 == 'eq' && cellValue != value1){
  1147. return false;
  1148. }
  1149. if(type2 == 'ne' && cellValue == value1){
  1150. return false;
  1151. }
  1152. if(type2 == 'gt' && cellValue <= value1){
  1153. return false;
  1154. }
  1155. if(type2 == 'lt' && cellValue >= value1){
  1156. return false;
  1157. }
  1158. if(type2 == 'gte' && cellValue < value1){
  1159. return false;
  1160. }
  1161. if(type2 == 'lte' && cellValue > value1){
  1162. return false;
  1163. }
  1164. }
  1165. else if(type == 'text_content'){
  1166. cellValue = cellValue.toString();
  1167. value1 = value1.toString();
  1168. if(type2 == 'include' && cellValue.indexOf(value1) == -1){
  1169. return false;
  1170. }
  1171. if(type2 == 'exclude' && cellValue.indexOf(value1) > -1){
  1172. return false;
  1173. }
  1174. if(type2 == 'equal' && cellValue != value1){
  1175. return false;
  1176. }
  1177. }
  1178. else if(type == 'text_length'){
  1179. cellValue = cellValue.toString().length;
  1180. value1 = Number(value1);
  1181. value2 = Number(value2);
  1182. if(type2 == 'bw' && (cellValue < value1 || cellValue > value2)){
  1183. return false;
  1184. }
  1185. if(type2 == 'nb' && (cellValue >= value1 && cellValue <= value2)){
  1186. return false;
  1187. }
  1188. if(type2 == 'eq' && cellValue != value1){
  1189. return false;
  1190. }
  1191. if(type2 == 'ne' && cellValue == value1){
  1192. return false;
  1193. }
  1194. if(type2 == 'gt' && cellValue <= value1){
  1195. return false;
  1196. }
  1197. if(type2 == 'lt' && cellValue >= value1){
  1198. return false;
  1199. }
  1200. if(type2 == 'gte' && cellValue < value1){
  1201. return false;
  1202. }
  1203. if(type2 == 'lte' && cellValue > value1){
  1204. return false;
  1205. }
  1206. }
  1207. else if(type == 'date'){
  1208. if(!isdatetime(cellValue)){
  1209. return false;
  1210. }
  1211. if(type2 == 'bw' && (diff(cellValue, value1) < 0 || diff(cellValue, value2) > 0)){
  1212. return false;
  1213. }
  1214. if(type2 == 'nb' && (diff(cellValue, value1) >= 0 && diff(cellValue, value2) <= 0)){
  1215. return false;
  1216. }
  1217. if(type2 == 'eq' && diff(cellValue, value1) != 0){
  1218. return false;
  1219. }
  1220. if(type2 == 'ne' && diff(cellValue, value1) == 0){
  1221. return false;
  1222. }
  1223. if(type2 == 'bf' && diff(cellValue, value1) >= 0){
  1224. return false;
  1225. }
  1226. if(type2 == 'nbf' && diff(cellValue, value1) < 0){
  1227. return false;
  1228. }
  1229. if(type2 == 'af' && diff(cellValue, value1) <= 0){
  1230. return false;
  1231. }
  1232. if(type2 == 'naf' && diff(cellValue, value1) > 0){
  1233. return false;
  1234. }
  1235. }
  1236. else if(type == 'validity'){
  1237. if(type2 == 'card' && !validateIdCard(cellValue)){
  1238. return false;
  1239. }
  1240. if(type2 == 'phone' && !/^1[3456789]\d{9}$/.test(cellValue)){
  1241. return false;
  1242. }
  1243. }
  1244. return true;
  1245. },
  1246. dropdownListShow: function(){
  1247. $("#luckysheet-dataVerification-showHintBox").hide();
  1248. let _this = this;
  1249. let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
  1250. let rowIndex = last.row_focus;
  1251. let colIndex = last.column_focus;
  1252. let row = Store.visibledatarow[rowIndex],
  1253. row_pre = rowIndex == 0 ? 0 : Store.visibledatarow[rowIndex - 1];
  1254. let col = Store.visibledatacolumn[colIndex],
  1255. col_pre = colIndex == 0 ? 0 : Store.visibledatacolumn[colIndex - 1];
  1256. let margeset = menuButton.mergeborer(Store.flowdata, rowIndex, colIndex);
  1257. if(!!margeset){
  1258. row = margeset.row[1];
  1259. row_pre = margeset.row[0];
  1260. col = margeset.column[1];
  1261. col_pre = margeset.column[0];
  1262. }
  1263. let item = _this.dataVerification[rowIndex + '_' + colIndex];
  1264. let list = _this.getDropdownList(item.value1);
  1265. let optionHtml = '';
  1266. if (item.type === 'dropdown' && item.type2) {
  1267. // 下拉多选的情况下 将已经选择的标出来
  1268. let cellValue = getcellvalue(rowIndex, colIndex, null);
  1269. let valueArr = isRealNull(cellValue) ? [] : cellValue.split(',');
  1270. list.forEach(i => {
  1271. let checked = valueArr.indexOf(i) !== -1;
  1272. optionHtml += `<div class="dropdown-List-item luckysheet-mousedown-cancel multi${checked ? ' checked': ''}">${i}</div>`;
  1273. });
  1274. } else {
  1275. list.forEach(i => {
  1276. optionHtml += `<div class="dropdown-List-item luckysheet-mousedown-cancel">${i}</div>`;
  1277. });
  1278. }
  1279. $("#luckysheet-dataVerification-dropdown-List")
  1280. .html(optionHtml)
  1281. .prop("data-index", rowIndex + '_' + colIndex)
  1282. .show()
  1283. .css({
  1284. 'width': col - col_pre - 1,
  1285. 'left': col_pre,
  1286. 'top': row,
  1287. });
  1288. let myh = $("#luckysheet-dataVerification-dropdown-List").outerHeight();
  1289. let currentWinH = $("#luckysheet-cell-main")[0].scrollHeight;
  1290. if(row + myh > currentWinH - 42 - 6){
  1291. $("#luckysheet-dataVerification-dropdown-List").css({
  1292. 'top': row_pre - myh,
  1293. })
  1294. }
  1295. },
  1296. getDropdownList: function(txt){
  1297. let list = [];
  1298. if(formula.iscelldata(txt)){
  1299. let range = formula.getcellrange(txt);
  1300. let d = Store.luckysheetfile[getSheetIndex(range.sheetIndex)].data;
  1301. for(let r = range.row[0]; r <= range.row[1]; r++){
  1302. for(let c = range.column[0]; c <= range.column[1]; c++){
  1303. if(d[r] == null){
  1304. continue;
  1305. }
  1306. let cell = d[r][c];
  1307. if(cell == null || cell.v == null){
  1308. continue;
  1309. }
  1310. let v = cell.m || cell.v;
  1311. if(!list.includes(v)){
  1312. list.push(v);
  1313. }
  1314. }
  1315. }
  1316. }
  1317. else{
  1318. let arr = txt.split(",");
  1319. for(let i = 0; i < arr.length; i++){
  1320. let v = arr[i];
  1321. if(v.length == 0){
  1322. continue;
  1323. }
  1324. if(!list.includes(v)){
  1325. list.push(v);
  1326. }
  1327. }
  1328. }
  1329. return list;
  1330. },
  1331. checkboxChange: function(r, c){
  1332. let _this = this;
  1333. let historyDataVerification = $.extend(true, {}, _this.dataVerification);
  1334. let currentDataVerification = $.extend(true, {}, _this.dataVerification);
  1335. let item = currentDataVerification[r + '_' + c];
  1336. item.checked = !item.checked;
  1337. let value = item.value2;
  1338. if(item.checked){
  1339. value = item.value1;
  1340. }
  1341. let d = editor.deepCopyFlowData(Store.flowdata);
  1342. setcellvalue(r, c, d, value);
  1343. _this.refOfCheckbox(
  1344. historyDataVerification,
  1345. currentDataVerification,
  1346. Store.currentSheetIndex,
  1347. d,
  1348. { "row": [r, r], "column": [c, c] }
  1349. );
  1350. },
  1351. ref: function(historyDataVerification, currentDataVerification, sheetIndex){
  1352. let _this = this;
  1353. if (Store.clearjfundo) {
  1354. Store.jfundo.length = 0;
  1355. let redo = {};
  1356. redo["type"] = "updateDataVerification";
  1357. redo["sheetIndex"] = sheetIndex;
  1358. redo["historyDataVerification"] = historyDataVerification;
  1359. redo["currentDataVerification"] = currentDataVerification;
  1360. Store.jfredo.push(redo);
  1361. }
  1362. _this.dataVerification = currentDataVerification;
  1363. Store.luckysheetfile[getSheetIndex(sheetIndex)].dataVerification = currentDataVerification;
  1364. //共享编辑模式
  1365. if(server.allowUpdate){
  1366. server.saveParam("all", sheetIndex, currentDataVerification, { "k": "dataVerification" });
  1367. }
  1368. setTimeout(function () {
  1369. luckysheetrefreshgrid();
  1370. }, 1);
  1371. },
  1372. refOfCheckbox: function(historyDataVerification, currentDataVerification, sheetIndex, d, range){
  1373. let _this = this;
  1374. if (Store.clearjfundo) {
  1375. Store.jfundo.length = 0;
  1376. let redo = {};
  1377. redo["type"] = "updateDataVerificationOfCheckbox";
  1378. redo["sheetIndex"] = sheetIndex;
  1379. redo["historyDataVerification"] = historyDataVerification;
  1380. redo["currentDataVerification"] = currentDataVerification;
  1381. redo["data"] = Store.flowdata;
  1382. redo["curData"] = d;
  1383. redo["range"] = range;
  1384. Store.jfredo.push(redo);
  1385. }
  1386. _this.dataVerification = currentDataVerification;
  1387. Store.luckysheetfile[getSheetIndex(sheetIndex)].dataVerification = currentDataVerification;
  1388. Store.flowdata = d;
  1389. editor.webWorkerFlowDataCache(Store.flowdata);//worker存数据
  1390. Store.luckysheetfile[getSheetIndex(sheetIndex)].data = Store.flowdata;
  1391. //共享编辑模式
  1392. if(server.allowUpdate){
  1393. server.saveParam("all", sheetIndex, currentDataVerification, { "k": "dataVerification" });
  1394. server.historyParam(Store.flowdata, sheetIndex, range);
  1395. }
  1396. setTimeout(function () {
  1397. luckysheetrefreshgrid();
  1398. }, 1);
  1399. },
  1400. }
  1401. function validateIdCard(idCard) {
  1402. // 15位和18位身份证号码的正则表达式
  1403. var regIdCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
  1404. // 如果通过该验证,说明身份证格式正确,但准确性还需计算
  1405. if (regIdCard.test(idCard)) {
  1406. if (idCard.length == 18) {
  1407. var idCardWi = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2); // 将前17位加权因子保存在数组里
  1408. var idCardY = new Array(1, 0, 10, 9, 8, 7, 6, 5, 4, 3, 2); // 这是除以11后,可能产生的11位余数、验证码,也保存成数组
  1409. var idCardWiSum = 0; // 用来保存前17位各自乖以加权因子后的总和
  1410. for (var i = 0; i < 17; i++) {
  1411. idCardWiSum += idCard.substring(i, i + 1) * idCardWi[i];
  1412. }
  1413. var idCardMod = idCardWiSum % 11; // 计算出校验码所在数组的位置
  1414. var idCardLast = idCard.substring(17); // 得到最后一位身份证号码
  1415. // 如果等于2,则说明校验码是10,身份证号码最后一位应该是X
  1416. if (idCardMod == 2) {
  1417. if (idCardLast == "X" || idCardLast == "x") {
  1418. return true;
  1419. } else {
  1420. return false;
  1421. }
  1422. } else {
  1423. // 用计算出的验证码与最后一位身份证号码匹配,如果一致,说明通过,否则是无效的身份证号码
  1424. if (idCardLast == idCardY[idCardMod]) {
  1425. return true;
  1426. } else {
  1427. return false;
  1428. }
  1429. }
  1430. }
  1431. } else {
  1432. return false;
  1433. }
  1434. }
  1435. export default dataVerificationCtrl;