Browse Source

完善表头保存

dev-xx
qb 9 months ago
parent
commit
c75240bbe9
  1. 27
      src/api/basic/table.js
  2. 47
      src/components/edittablehead/index.vue

27
src/api/basic/table.js

@ -0,0 +1,27 @@
import request from '@/axios';
/**
* 获取表格表头数据
* @param {*} { tableKey -- key }
* @returns
*/
export const getTableSeting = params => {
return request({
url: '/api/logpm-basic/commonTable/getTableSeting',
method: 'get',
params,
});
};
/**
* 设置表格表头数据
* @param {*} { tableKey -- key, tableSetCongig -- 设置的内容 }
* @returns
*/
export const postSaveTableSeting = data => {
return request({
url: '/api/logpm-basic/commonTable/saveTableSeting',
method: 'post',
data,
});
};

47
src/components/edittablehead/index.vue

@ -46,10 +46,10 @@
import { ref, watchEffect, onMounted, watch, inject, nextTick } from 'vue';
import type { PropType } from 'vue';
import { useRoute } from 'vue-router';
import { getTableSeting, postSaveTableSeting } from '@/api/basic/table';
const functions = inject('functions') as any;
import Sortable from 'sortablejs';
import { handleClearTableQuery } from '@/utils/util';
import { getObjType, handleClearTableQuery } from '@/utils/util';
interface TableColumnType {
/** 表格列的key */
prop: string;
@ -128,13 +128,36 @@ const columnRef = ref([...props.modelValue]);
const tableEl1 = ref();
const _arr = functions.getStorage($route.fullPath + props.columnListName);
// const _arr = functions.getStorage($route.fullPath + props.columnListName);
if (_arr) {
columnRef.value = [..._arr];
handleClearTableQuery(_arr);
emit('update:modelValue', _arr);
}
// if (_arr) {
// columnRef.value = [..._arr];
// handleClearTableQuery(_arr);
// emit('update:modelValue', _arr);
// }
const initTable = async () => {
try {
const submitData = { tableKey: $route.fullPath + props.columnListName };
const res = await getTableSeting(submitData);
const { code, data } = res.data;
if (code !== 200) return;
const _arr = JSON.parse(data);
if (getObjType(_arr) !== 'array') return;
console.log('_arr :>> ', _arr);
columnRef.value = [..._arr];
handleClearTableQuery(_arr);
emit('update:modelValue', _arr);
} catch (error) {
console.log('error :>> ', error);
}
};
initTable();
onMounted(() => {
for (let index = 0; index < props.modelValue.length; index++) {
@ -173,7 +196,11 @@ const initSortable = () => {
const currRow = arr.splice(oldIndex, 1)[0];
arr.splice(newIndex, 0, currRow);
functions.setStorage($route.fullPath + props.columnListName, arr);
// functions.setStorage($route.fullPath + props.columnListName, arr);
postSaveTableSeting({
tableKey: $route.fullPath + props.columnListName,
tableSetCongig: JSON.stringify(arr),
});
// emit('update:modelValue', arr);
// nextTick(() => {
// emit('setcolum', arr, 4);
@ -212,7 +239,5 @@ let headtop = ref<headtoptype[]>([
// width:'150'
},
]);
setTimeout(() => {}, 2000);
</script>
<style lang="scss"></style>

Loading…
Cancel
Save