|
@@ -3,8 +3,15 @@ import {
|
|
|
getColumn,
|
|
|
delColumn
|
|
|
} from "@/api/saveColumn";
|
|
|
+import {validatenull} from './validate'
|
|
|
+export const arraySort = (list = [], prop, callback) => {
|
|
|
+ return list.filter(ele => !validatenull(ele[prop])).sort((a, b) => callback(a, b)).concat(list.filter(ele => validatenull(ele[prop])));
|
|
|
+}
|
|
|
|
|
|
export async function getColumnData(columnKey, mainOption) {
|
|
|
+ mainOption.column.forEach((item,index)=>{
|
|
|
+ item.index=index+1
|
|
|
+ })
|
|
|
let option
|
|
|
const localData = JSON.parse(localStorage.getItem(columnKey));
|
|
|
if (localData != null) {
|
|
@@ -16,9 +23,11 @@ export async function getColumnData(columnKey, mainOption) {
|
|
|
option = res.data.data ? JSON.parse(res.data.data.jsonMessage)?JSON.parse(res.data.data.jsonMessage):mainOption: mainOption;
|
|
|
localStorage.setItem(columnKey, JSON.stringify(option));
|
|
|
}
|
|
|
+ option.column=arraySort(option.column, 'index', (a, b) => a.index - b.index)
|
|
|
return option
|
|
|
}
|
|
|
export async function saveColumnData(columnKey, option) {
|
|
|
+ option.column=arraySort(option.column, 'index', (a, b) => a.index - b.index)
|
|
|
let res = await saveColumn({
|
|
|
fileName: columnKey,
|
|
|
jsonMessage: JSON.stringify(option)
|
|
@@ -31,6 +40,9 @@ export async function saveColumnData(columnKey, option) {
|
|
|
}
|
|
|
}
|
|
|
export async function delColumnData(columnKey, option) {
|
|
|
+ option.column.forEach((item,index)=>{
|
|
|
+ item.index=index+1
|
|
|
+ })
|
|
|
let res = await delColumn({
|
|
|
fileName: columnKey
|
|
|
})
|