diff --git a/docs/zh/guide/api.md b/docs/zh/guide/api.md index a0ad62efe..a0229c608 100644 --- a/docs/zh/guide/api.md +++ b/docs/zh/guide/api.md @@ -1261,46 +1261,39 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开 `conditionName`可能的值有: - + `"greaterThan"`: 大于 - + `"lessThan"`: 小于 - + `"betweenness"`: 介于 - + `"equal"`: 等于 - + `"textContains"`: 文本包含 - + `"occurrenceDate"`: 发生日期 - + `"duplicateValue"`: 重复值 - + `"top"`: 前 N 项(可以在conditionValue中设置其他值) - + `"topPercent"`: 前 N%(可以在conditionValue中设置其他值) - + `"last"`: 后 N 项(可以在conditionValue中设置其他值) - + `"lastPercent"`: 后 N%(可以在conditionValue中设置其他值) - + `"AboveAverage"`: 高于平均值 - + `"SubAverage"`: 低于平均值 + + `"greaterThan"`: 大于(conditionValue值为 数值或单元格范围) + + `"lessThan"`: 小于(conditionValue值为 数值或单元格范围) + + `"betweenness"`: 介于(conditionValue值为 数值或单元格范围) + + `"equal"`: 等于(conditionValue值为 数值或单元格范围) + + `"textContains"`: 文本包含(conditionValue值为 文本或单元格范围) + + `"occurrenceDate"`: 发生日期(conditionValue值为 日期) + + `"duplicateValue"`: 重复值(conditionValue值为 '0':重复值, '1':唯一值) + + `"top10"`: 前 N 项(conditionValue值为 1~1000) + + `"top10%"`: 前 N%(conditionValue值为 1~1000) + + `"last10"`: 后 N 项(conditionValue值为 1~1000) + + `"last10%"`: 后 N%(conditionValue值为 1~1000) + + `"AboveAverage"`: 高于平均值(conditionValue可为空数组) + + `"SubAverage"`: 低于平均值(conditionValue可为空数组) - - {Object} [conditionValue]: 可以设置条件单元格或者条件值 - 取值规则 + - {Array} [conditionValue]: 可以设置条件单元格或者条件值 + 取值规则 (条件值数组最少一个值,最多两个值) ```js - { - type: 'value', - content: [2] - } + [2] ``` - 或者 + 或者 (若值为单元格范围,则取左上角单元格值) ```js - { - type: 'range', - content: ['A1'] - } + ['A1'] ``` - {PlainObject} [setting]: 可选参数 - + {Object | Array} [format]: 颜色设置 + + {Object} [format]: 颜色设置 - * `type`为`default`时,应设置文本颜色和单元格颜色;默认值为` { + * 设置文本颜色和单元格颜色;默认值为` { "textColor": "#000000", "cellColor": "#ff0000" }` - + {Boolean} [isEdit]: 是否在修改条件格式规则;默认为 `false` - + {Array | Object | String} [range]: 选区范围,支持选区的格式为`"A1:B2"`、`"sheetName!A1:B2"`或者`{row:[0,1],column:[0,1]}`,允许多个选区组成的数组;默认为当前选区 + + {Array | Object | String} [cellrange]: 选区范围,支持选区的格式为`"A1:B2"`、`"sheetName!A1:B2"`或者`{row:[0,1],column:[0,1]}`,允许多个选区组成的数组;默认为当前选区 + {Number} [order]: 工作表索引;默认值为当前工作表索引 + {Function} [success]: 操作结束的回调函数 @@ -1372,7 +1365,7 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开 - {PlainObject} [setting]: 可选参数 - + {Object | Array} [format]: 颜色设置 + + {Array | String} [format]: 颜色设置 * `type`为`dataBar`时,应设置渐变色;默认值为蓝-白渐变` ["#638ec6", "#ffffff"]` @@ -1392,7 +1385,7 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开 ["#d6007b"] //紫色 数据条 ``` - * `type`为`icons`时,应设置图标类型;默认值为"threeWayArrowColor":三向箭头彩色, + * `type`为`icons`时,应设置图标类型;默认值为"threeWayArrowMultiColor":三向箭头彩色, 可取值为: @@ -1459,8 +1452,7 @@ Luckysheet针对常用的数据操作需求,开放了主要功能的API,开 ["rgb(255, 235, 132)", "rgb(99, 190, 123)"] //黄-绿色阶 ``` - + {Boolean} [isEdit]: 是否在修改条件格式规则;默认为 `false` - + {Array | Object | String} [range]: 选区范围,支持选区的格式为`"A1:B2"`、`"sheetName!A1:B2"`或者`{row:[0,1],column:[0,1]}`,允许多个选区组成的数组;默认为当前选区 + + {Array | Object | String} [cellrange]: 选区范围,支持选区的格式为`"A1:B2"`、`"sheetName!A1:B2"`或者`{row:[0,1],column:[0,1]}`,允许多个选区组成的数组;默认为当前选区 + {Number} [order]: 工作表索引;默认值为当前工作表索引 + {Function} [success]: 操作结束的回调函数 diff --git a/src/controllers/conditionformat.js b/src/controllers/conditionformat.js index 1f1ac422f..657d50a00 100644 --- a/src/controllers/conditionformat.js +++ b/src/controllers/conditionformat.js @@ -428,7 +428,7 @@ const conditionformat = { } } else if(rangeArr.length == 0){ - if(isNaN(v) || v == ""){ + if(v == ""){ _this.infoDialog(conditionformat_Text.conditionValueCanOnly, ""); return; } @@ -478,7 +478,7 @@ const conditionformat = { return; } - conditionValue.push(v); + conditionValue.push(parseInt(v)); } else if(index == 3){ //平均值 if(type1 == "AboveAverage"){ @@ -1418,6 +1418,8 @@ const conditionformat = { getRangeByTxt: function(txt){ let range = []; + txt = txt.toString(); + if(txt.indexOf(",") != -1){ let arr = txt.split(","); for(let i = 0; i < arr.length; i++){ @@ -1432,7 +1434,7 @@ const conditionformat = { } else{ if(formula.iscelldata(txt)){ - range.push(formula.getcellrange(txt)); + range.push(formula.getcellrange(txt.tos)); } } diff --git a/src/global/api.js b/src/global/api.js index 370f0a78c..fbb26d638 100644 --- a/src/global/api.js +++ b/src/global/api.js @@ -18,6 +18,7 @@ import { getdatabyselection, getcellvalue } from "./getdata"; import { luckysheetrefreshgrid, jfrefreshgrid, jfrefreshgrid_rhcw } from "./refresh"; import { luckysheetDeleteCell, luckysheetextendtable, luckysheetdeletetable } from "./extend"; import { isRealNull, valueIsError, isRealNum, isEditMode, hasPartMC } from "./validate"; +import { isdatetime, diff } from "./datecontroll"; import server from "../controllers/server"; import selection from "../controllers/selection"; @@ -25,10 +26,12 @@ import luckysheetConfigsetting from "../controllers/luckysheetConfigsetting"; import luckysheetFreezen from "../controllers/freezen"; import luckysheetsizeauto from '../controllers/resize'; import sheetmanage from '../controllers/sheetmanage'; +import conditionformat from '../controllers/conditionformat'; import { luckysheet_searcharray } from "../controllers/sheetSearch"; import { selectIsOverlap } from '../controllers/select'; import { sheetHTML } from '../controllers/constant'; + const IDCardReg = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i; /** @@ -2261,6 +2264,549 @@ export function setRangeSortMulti(hasTitle, sort, options = {}) { } } + +/** + * 为指定索引的工作表,选定的范围开启条件格式,根据设置的条件格式规则突出显示部分单元格,返回开启条件格式后的数据。 + * @param {String} conditionName 条件格式规则类型 + * @param {Object} conditionValue 可以设置条件单元格或者条件值 + * @param {Object} options 可选参数 + * @param {Object} options.format 颜色设置 + * @param {Array | Object | String} options.cellrange 选区范围 + * @param {Number} options.order 工作表索引;默认值为当前工作表索引 + * @param {Function} options.success 操作结束的回调函数 + */ +export function setRangeConditionalFormatDefault(conditionName, conditionValue, options = {}) { + let conditionNameValues = [ + 'greaterThan', + 'lessThan', + 'betweenness', + 'equal', + 'textContains', + 'occurrenceDate', + 'duplicateValue', + 'top10', + 'top10%', + 'last10', + 'last10%', + 'AboveAverage', + 'SubAverage' + ]; + + if(!conditionName || !conditionNameValues.includes(conditionName)){ + return tooltip.info('The conditionName parameter is invalid.', ''); + } + + if(getObjType(conditionValue) != 'array' || conditionValue.length == 0){ + return tooltip.info('The conditionValue parameter is invalid.', ''); + } + + let { + format = { + "textColor": "#000000", + "cellColor": "#ff0000" + }, + cellrange = Store.luckysheet_select_save, + order = getSheetIndex(Store.currentSheetIndex), + success + } = {...options} + + let file = Store.luckysheetfile[order]; + let data = file.data; + + if(file == null){ + return tooltip.info('Incorrect worksheet index', ''); + } + + const conditionformat_Text = locale().conditionformat; + + let conditionRange = [], conditionValue2 = []; + + if(conditionName == 'betweenness'){ + let v1 = conditionValue[0]; + let v2 = conditionValue[1]; + + //条件值是否是选区 + let rangeArr1 = conditionformat.getRangeByTxt(v1); + if(rangeArr1.length > 1){ + conditionformat.infoDialog(conditionformat_Text.onlySingleCell, ""); + return; + } + else if(rangeArr1.length == 1){ + let r1 = rangeArr1[0].row[0], r2 = rangeArr1[0].row[1]; + let c1 = rangeArr1[0].column[0], c2 = rangeArr1[0].column[1]; + + if(r1 == r2 && c1 == c2){ + v1 = getcellvalue(r1, c1, data); + + conditionRange.push({ "row": rangeArr1[0].row, "column": rangeArr1[0].column }); + conditionValue2.push(v1); + } + else{ + conditionformat.infoDialog(conditionformat_Text.onlySingleCell, ""); + return; + } + } + else if(rangeArr1.length == 0){ + if(isNaN(v1) || v1 == ""){ + conditionformat.infoDialog(conditionformat_Text.conditionValueCanOnly, ""); + return; + } + else{ + conditionValue2.push(v1); + } + } + + let rangeArr2 = conditionformat.getRangeByTxt(v2); + if(rangeArr2.length > 1){ + conditionformat.infoDialog(conditionformat_Text.onlySingleCell, ""); + return; + } + else if(rangeArr2.length == 1){ + let r1 = rangeArr2[0].row[0], r2 = rangeArr2[0].row[1]; + let c1 = rangeArr2[0].column[0], c2 = rangeArr2[0].column[1]; + + if(r1 == r2 && c1 == c2){ + v2 = getcellvalue(r1, c1, data); + + conditionRange.push({ "row": rangeArr2[0].row, "column": rangeArr2[0].column }); + conditionValue2.push(v2); + } + else{ + conditionformat.infoDialog(conditionformat_Text.onlySingleCell, ""); + return; + } + } + else if(rangeArr2.length == 0){ + if(isNaN(v2) || v2 == ""){ + conditionformat.infoDialog(conditionformat_Text.conditionValueCanOnly, ""); + return; + } + else{ + conditionValue2.push(v2); + } + } + } + else if(conditionName == 'greaterThan' || conditionName == 'lessThan' || conditionName == 'equal'){ + let v = conditionValue[0]; + + //条件值是否是选区 + let rangeArr = conditionformat.getRangeByTxt(v); + if(rangeArr.length > 1){ + conditionformat.infoDialog(conditionformat_Text.onlySingleCell, ""); + return; + } + else if(rangeArr.length == 1){ + let r1 = rangeArr[0].row[0], r2 = rangeArr[0].row[1]; + let c1 = rangeArr[0].column[0], c2 = rangeArr[0].column[1]; + + if(r1 == r2 && c1 == c2){ + v = getcellvalue(r1, c1, data); + + conditionRange.push({ "row": rangeArr[0].row, "column": rangeArr[0].column }); + conditionValue2.push(v); + } + else{ + conditionformat.infoDialog(conditionformat_Text.onlySingleCell, ""); + return; + } + } + else if(rangeArr.length == 0){ + if(isNaN(v) || v == ""){ + conditionformat.infoDialog(conditionformat_Text.conditionValueCanOnly, ""); + return; + } + else{ + conditionValue2.push(v); + } + } + } + else if(conditionName == 'textContains'){ + let v = conditionValue[0]; + + //条件值是否是选区 + let rangeArr = conditionformat.getRangeByTxt(v); + if(rangeArr.length > 1){ + conditionformat.infoDialog(conditionformat_Text.onlySingleCell, ""); + return; + } + else if(rangeArr.length == 1){ + let r1 = rangeArr[0].row[0], r2 = rangeArr[0].row[1]; + let c1 = rangeArr[0].column[0], c2 = rangeArr[0].column[1]; + + if(r1 == r2 && c1 == c2){ + v = getcellvalue(r1, c1, data); + + conditionRange.push({ "row": rangeArr[0].row, "column": rangeArr[0].column }); + conditionValue2.push(v); + } + else{ + conditionformat.infoDialog(conditionformat_Text.onlySingleCell, ""); + return; + } + } + else if(rangeArr.length == 0){ + if(v == ""){ + conditionformat.infoDialog(conditionformat_Text.conditionValueCanOnly, ""); + return; + } + else{ + conditionValue2.push(v); + } + } + } + else if(conditionName == 'occurrenceDate'){ + let v1 = conditionValue[0]; + let v2 = conditionValue[1]; + + if(!isdatetime(v1) || !isdatetime(v2)){ + return tooltip.info('The conditionValue parameter is invalid.', ''); + } + + let v; + if(diff(v1, v2) > 0){ + v = moment(v2).format("YYYY/MM/DD") + "-" + moment(v1).format("YYYY/MM/DD"); + } + else{ + v = moment(v1).format("YYYY/MM/DD") + "-" + moment(v2).format("YYYY/MM/DD"); + } + + conditionValue2.push(v); + } + else if(conditionName == 'duplicateValue'){ + let v = conditionValue[0]; + + if(v != '0' || v != '1'){ + return tooltip.info('The conditionValue parameter is invalid.', ''); + } + + conditionValue2.push(v); + } + else if(conditionName == 'top10' || conditionName == 'top10%' || conditionName == 'last10' || conditionName == 'last10%'){ + let v = conditionValue[0]; + + if(parseInt(v) != v || parseInt(v) < 1 || parseInt(v) > 1000){ + conditionformat.infoDialog(conditionformat_Text.pleaseEnterInteger, ""); + return; + } + + conditionValue2.push(parseInt(v)); + } + else if(conditionName == 'AboveAverage' || conditionName == 'SubAverage'){ + conditionValue2.push(conditionName); + } + + if(!format.hasOwnProperty("textColor") || !format.hasOwnProperty("cellColor")){ + return tooltip.info('The format parameter is invalid.', ''); + } + + if(getObjType(cellrange) == 'string'){ + cellrange = conditionformat.getRangeByTxt(cellrange); + } + else if(getObjType(cellrange) == 'object'){ + cellrange = [cellrange]; + } + + let rule = { + "type": "default", + "cellrange": cellrange, + "format": format, + "conditionName": conditionName, + "conditionRange": conditionRange, + "conditionValue": conditionValue2 + }; + + //保存之前的规则 + let fileH = $.extend(true, [], Store.luckysheetfile); + let historyRules = conditionformat.getHistoryRules(fileH); + + //保存当前的规则 + let ruleArr = file["luckysheet_conditionformat_save"] || []; + ruleArr.push(rule); + file["luckysheet_conditionformat_save"] = ruleArr; + + let fileC = $.extend(true, [], Store.luckysheetfile); + let currentRules = conditionformat.getCurrentRules(fileC); + + //刷新一次表格 + conditionformat.ref(historyRules, currentRules); + + //发送给后台 + if(server.allowUpdate){ + server.saveParam("all", file.index, ruleArr, { "k": "luckysheet_conditionformat_save" }); + } + + if (success && typeof success === 'function') { + success(); + } +} + + +/** + * 为指定索引的工作表,选定的范围开启条件格式,返回开启条件格式后的数据。 + * @param {String} type 条件格式规则类型 + * @param {Object} options 可选参数 + * @param {Array | String} options.format 颜色设置 + * @param {Array | Object | String} options.cellrange 选区范围 + * @param {Number} options.order 工作表索引;默认值为当前工作表索引 + * @param {Function} options.success 操作结束的回调函数 + */ +export function setRangeConditionalFormat(type, options = {}) { + let typeValues = [ + 'dataBar', + 'colorGradation', + 'icons' + ]; + + if(!type || !typeValues.includes(type)){ + return tooltip.info('The type parameter is invalid.', ''); + } + + let { + format, + cellrange = Store.luckysheet_select_save, + order = getSheetIndex(Store.currentSheetIndex), + success + } = {...options} + + let file = Store.luckysheetfile[order]; + + if(file == null){ + return tooltip.info('Incorrect worksheet index', ''); + } + + if(type == 'dataBar'){ + if(format == null){ + format = ["#638ec6", "#ffffff"]; + } + + if(getObjType(format) != 'array' || format.length < 1 || format.length > 2){ + return tooltip.info('The format parameter is invalid.', ''); + } + } + else if(type == 'colorGradation'){ + if(format == null){ + format = ["rgb(99, 190, 123)", "rgb(255, 235, 132)", "rgb(248, 105, 107)"]; + } + + if(getObjType(format) != 'array' || format.length < 2 || format.length > 3){ + return tooltip.info('The format parameter is invalid.', ''); + } + } + else if(type == 'icons'){ + if(format == null){ + format = "threeWayArrowMultiColor"; + } + + let formatValues = [ + 'threeWayArrowMultiColor', + 'threeTriangles', + 'fourWayArrowMultiColor', + 'fiveWayArrowMultiColor', + 'threeWayArrowGrayColor', + 'fourWayArrowGrayColor', + 'fiveWayArrowGrayColor', + 'threeColorTrafficLightRimless', + 'threeSigns', + 'greenRedBlackGradient', + 'threeColorTrafficLightBordered', + 'fourColorTrafficLight', + 'threeSymbolsCircled', + 'tricolorFlag', + 'threeSymbolsnoCircle', + 'threeStars', + 'fiveQuadrantDiagram', + 'fiveBoxes', + 'grade4', + 'grade5' + ]; + + if(getObjType(format) != 'string' || !formatValues.includes(format)){ + return tooltip.info('The format parameter is invalid.', ''); + } + + switch (format) { + case 'threeWayArrowMultiColor': + format = { + "len": 3, + "leftMin": 0, + "top": 0 + }; + break; + case 'threeTriangles': + format = { + "len": 3, + "leftMin": 0, + "top": 1 + }; + break; + case 'fourWayArrowMultiColor': + format = { + "len": 4, + "leftMin": 0, + "top": 2 + }; + break; + case 'fiveWayArrowMultiColor': + format = { + "len": 5, + "leftMin": 0, + "top": 3 + }; + break; + case 'threeWayArrowGrayColor': + format = { + "len": 3, + "leftMin": 5, + "top": 0 + }; + break; + case 'fourWayArrowGrayColor': + format = { + "len": 4, + "leftMin": 5, + "top": 1 + }; + break; + case 'fiveWayArrowGrayColor': + format = { + "len": 5, + "leftMin": 5, + "top": 2 + }; + break; + case 'threeColorTrafficLightRimless': + format = { + "len": 3, + "leftMin": 0, + "top": 4 + }; + break; + case 'threeSigns': + format = { + "len": 3, + "leftMin": 0, + "top": 5 + }; + break; + case 'greenRedBlackGradient': + format = { + "len": 4, + "leftMin": 0, + "top": 6 + }; + break; + case 'threeColorTrafficLightBordered': + format = { + "len": 3, + "leftMin": 5, + "top": 4 + }; + break; + case 'fourColorTrafficLight': + format = { + "len": 4, + "leftMin": 5, + "top": 5 + }; + break; + case 'threeSymbolsCircled': + format = { + "len": 3, + "leftMin": 0, + "top": 7 + }; + break; + case 'tricolorFlag': + format = { + "len": 3, + "leftMin": 0, + "top": 8 + }; + break; + case 'threeSymbolsnoCircle': + format = { + "len": 3, + "leftMin": 5, + "top": 7 + }; + break; + case 'threeStars': + format = { + "len": 3, + "leftMin": 0, + "top": 9 + }; + break; + case 'fiveQuadrantDiagram': + format = { + "len": 5, + "leftMin": 0, + "top": 10 + }; + break; + case 'fiveBoxes': + format = { + "len": 5, + "leftMin": 0, + "top": 11 + }; + break; + case 'grade4': + format = { + "len": 4, + "leftMin": 5, + "top": 9 + }; + break; + case 'grade5': + format = { + "len": 5, + "leftMin": 5, + "top": 10 + }; + break; + } + } + + if(getObjType(cellrange) == 'string'){ + cellrange = conditionformat.getRangeByTxt(cellrange); + } + else if(getObjType(cellrange) == 'object'){ + cellrange = [cellrange]; + } + + let rule = { + "type": type, + "cellrange": cellrange, + "format": format + }; + + //保存之前的规则 + let fileH = $.extend(true, [], Store.luckysheetfile); + let historyRules = conditionformat.getHistoryRules(fileH); + + //保存当前的规则 + let ruleArr = file["luckysheet_conditionformat_save"] || []; + ruleArr.push(rule); + file["luckysheet_conditionformat_save"] = ruleArr; + + let fileC = $.extend(true, [], Store.luckysheetfile); + let currentRules = conditionformat.getCurrentRules(fileC); + + //刷新一次表格 + conditionformat.ref(historyRules, currentRules); + + //发送给后台 + if(server.allowUpdate){ + server.saveParam("all", file.index, ruleArr, { "k": "luckysheet_conditionformat_save" }); + } + + if (success && typeof success === 'function') { + success(); + } +} + + /** * * @param {String} move 删除后,右侧还是下方的单元格移动 @@ -2780,8 +3326,11 @@ export function setSheetAdd(options = {}) { Store.luckysheetfile.splice(order, 0, sheetconfig); } + let orders = {}; + Store.luckysheetfile.forEach((item, i, arr) => { arr[i].order = i; + orders[item.index.toString()] = i; }) $("#luckysheet-sheet-area div.luckysheet-sheets-item").removeClass("luckysheet-sheets-item-active"); @@ -2790,6 +3339,7 @@ export function setSheetAdd(options = {}) { cleargridelement(true); server.saveParam("sha", null, $.extend(true, {}, sheetconfig)); + server.saveParam("shr", null, orders); if (Store.clearjfundo) { Store.jfundo = []; @@ -2802,6 +3352,103 @@ export function setSheetAdd(options = {}) { } sheetmanage.changeSheetExec(index, false, true); + + if (success && typeof success === 'function') { + success(); + } +} + + +/** + * 指定工作表向左边或右边移动一个位置,或者指定索引,返回指定的工作表对象 + * @param {String | Number} type 工作表移动方向或者移动的目标索引 + * @param {Object} options 可选参数 + * @param {Number} options.order 工作表索引;默认值为当前工作表索引 + * @param {Function} options.success 操作结束的回调函数 + */ +export function setSheetMove(type, options = {}) { + if(type != 'left' && type != 'right' && !isRealNum(type)){ + return tooltip.info("Type parameter not available", ""); + } + + if(isRealNum(type)){ + type = parseInt(type); + } + + let curOrder = getSheetIndex(Store.currentSheetIndex); + let { + order = curOrder, + success + } = {...options} + + let file = Store.luckysheetfile[order]; + + if(file == null){ + return tooltip.info("ncorrect worksheet index", ""); + } + + let sheetIndex = file.index; + + if(type == 'left'){ + if(order == 0){ + return; + } + + let prevIndex = Store.luckysheetfile[order - 1].index; + $("#luckysheet-sheets-item" + sheetIndex).insertBefore($("#luckysheet-sheets-item" + prevIndex)); + + Store.luckysheetfile.splice(order, 1); + Store.luckysheetfile.splice(order - 1, 0, file); + } + else if(type == 'right'){ + if(order == Store.luckysheetfile.length - 1){ + return; + } + + let nextIndex = Store.luckysheetfile[order + 1].index; + $("#luckysheet-sheets-item" + sheetIndex).insertAfter($("#luckysheet-sheets-item" + nextIndex)); + + Store.luckysheetfile.splice(order, 1); + Store.luckysheetfile.splice(order + 1, 0, file); + } + else{ + if(type < 0){ + type = 0; + } + + if(type > Store.luckysheetfile.length - 1){ + type = Store.luckysheetfile.length - 1; + } + + if(type == order){ + return; + } + + if(type < order){ + let prevIndex = Store.luckysheetfile[type].index; + $("#luckysheet-sheets-item" + sheetIndex).insertBefore($("#luckysheet-sheets-item" + prevIndex)); + } + else{ + let nextIndex = Store.luckysheetfile[type].index; + $("#luckysheet-sheets-item" + sheetIndex).insertAfter($("#luckysheet-sheets-item" + nextIndex)); + } + + Store.luckysheetfile.splice(order, 1); + Store.luckysheetfile.splice(type, 0, file); + } + + let orders = {}; + + Store.luckysheetfile.forEach((item, i, arr) => { + arr[i].order = i; + orders[item.index.toString()] = i; + }) + + server.saveParam("shr", null, orders); + + if (success && typeof success === 'function') { + success(); + } }