ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<script lang="ts" setup>
import { nextTick, reactive } from 'vue';
 
import { useMessage } from '@jnpf/hooks';
import { BasicModal, useModalInner } from '@jnpf/ui/modal';
 
import { cloneDeep } from 'lodash-es';
import Sortablejs from 'sortablejs';
 
import { useBaseStore } from '#/store';
 
interface State {
  list: any[];
  menuList: any[];
  appMenuList: any[];
  categoryList: any[];
  showType: string;
}
const emit = defineEmits(['register', 'change']);
const state = reactive<State>({
  list: [],
  menuList: [],
  appMenuList: [],
  categoryList: [],
  showType: '',
});
const { createMessage } = useMessage();
const baseStore = useBaseStore();
const [registerModal, { closeModal }] = useModalInner(init);
const columns = [
  { title: '拖动', dataIndex: 'drag', key: 'drag', align: 'center', width: 50 },
  { title: '名称', dataIndex: 'fullName', key: 'fullName', width: 250 },
  { title: '分类', dataIndex: 'category', key: 'category', width: 250 },
  { title: '隐藏', dataIndex: 'noShow', key: 'noShow', width: 70 },
  { title: '图标', dataIndex: 'icon', key: 'icon', width: 280 },
  { title: '图标背景色', dataIndex: 'iconBgColor', key: 'iconBgColor', width: 90 },
];
 
function init(data) {
  state.list = cloneDeep(data.data);
  state.menuList = data.menuList || [];
  state.appMenuList = data.appMenuList || [];
  state.menuList = data.showType || 'pc';
  getDictionaryData();
  nextTick(() => initSort());
}
async function getDictionaryData() {
  state.categoryList = (await baseStore.getDictionaryData('businessType')) as any[];
}
function initSort() {
  const searchTable: any = document.querySelector(`.carousel-table .ant-table-tbody`);
  Sortablejs.create(searchTable, {
    handle: '.drag-handler',
    animation: 150,
    easing: 'cubic-bezier(1, 0, 0, 1)',
    onStart: () => {},
    onEnd: ({ newIndex, oldIndex }: any) => {
      const currRow = state.list.splice(oldIndex, 1)[0];
      state.list.splice(newIndex, 0, currRow);
    },
  });
}
function handleSubmit() {
  for (let i = 0; i < state.list.length; i++) {
    const element = state.list[i];
    if (!element.fullName) return createMessage.warning('名称不能为空');
    if (!element.icon) return createMessage.warning('请选择图标');
    if (!element.iconBgColor) return createMessage.warning('请选择图标背景色');
  }
  emit('change', state.list);
  nextTick(() => closeModal());
}
</script>
<template>
  <BasicModal v-bind="$attrs" width="1000px" class="jnpf-modal-portal" @register="registerModal" title="选项设置" @ok="handleSubmit" destroy-on-close>
    <a-table :data-source="state.list" :columns="columns" size="small" :pagination="false" row-key="id" class="carousel-table">
      <template #bodyCell="{ column, record }">
        <template v-if="column.key === 'drag'">
          <i class="drag-handler icon-ym icon-ym-darg" title="点击拖动"></i>
        </template>
        <template v-if="column.key === 'fullName'">
          <jnpf-i18n-input v-model:value="record.fullName" v-model:i18n="record.fullNameI18nCode" placeholder="请输入名称" allow-clear :maxlength="50" />
        </template>
        <template v-if="column.key === 'category'">
          <jnpf-select v-model:value="record[column.key]" :options="state.categoryList" placeholder="请选择分类" multiple show-search allow-clear />
        </template>
        <template v-if="column.key === 'noShow'">
          <a-switch v-model:checked="record.noShow" />
        </template>
        <template v-if="column.key === 'icon'">
          <JnpfIconPicker v-model:value="record.icon" />
        </template>
        <template v-if="column.key === 'iconBgColor'">
          <jnpf-color-picker v-model:value="record.iconBgColor" size="small" />
        </template>
      </template>
    </a-table>
  </BasicModal>
</template>