Commit cf176091d5bdacd35476558de0bee987a070ceb6
Merge branch 'ww' into 'main'
feat: 产品详情物模型标识符列新增复制功能 See merge request yunteng/thingskit-front!497
Showing
2 changed files
with
53 additions
and
18 deletions
@@ -7,8 +7,10 @@ import { numberRule } from '/@/utils/rules'; | @@ -7,8 +7,10 @@ import { numberRule } from '/@/utils/rules'; | ||
7 | import { deviceConfigGetRuleChain } from '/@/api/device/deviceConfigApi'; | 7 | import { deviceConfigGetRuleChain } from '/@/api/device/deviceConfigApi'; |
8 | import { FormField, FunctionType } from './step/cpns/physical/cpns/config'; | 8 | import { FormField, FunctionType } from './step/cpns/physical/cpns/config'; |
9 | import { h } from 'vue'; | 9 | import { h } from 'vue'; |
10 | -import { Tag } from 'ant-design-vue'; | 10 | +import { Tag, Tooltip } from 'ant-design-vue'; |
11 | import { EventType, EventTypeColor, EventTypeName } from '../list/cpns/tabs/EventManage/config'; | 11 | import { EventType, EventTypeColor, EventTypeName } from '../list/cpns/tabs/EventManage/config'; |
12 | +import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard'; | ||
13 | +import { useMessage } from '/@/hooks/web/useMessage'; | ||
12 | 14 | ||
13 | export enum Mode { | 15 | export enum Mode { |
14 | CARD = 'card', | 16 | CARD = 'card', |
@@ -37,6 +39,14 @@ export enum ModelOfMatterPermission { | @@ -37,6 +39,14 @@ export enum ModelOfMatterPermission { | ||
37 | RELEASE = 'api:yt:things_model:release', | 39 | RELEASE = 'api:yt:things_model:release', |
38 | } | 40 | } |
39 | 41 | ||
42 | +const handleCopy = (value: string) => { | ||
43 | + const { createMessage } = useMessage(); | ||
44 | + const { clipboardRef, isSuccessRef } = useCopyToClipboard(value); | ||
45 | + clipboardRef.value = value; | ||
46 | + if (isSuccessRef.value) createMessage.success('复制成功~'); | ||
47 | + else createMessage.error('复制失败~'); | ||
48 | +}; | ||
49 | + | ||
40 | export const steps = [ | 50 | export const steps = [ |
41 | { | 51 | { |
42 | title: '产品', | 52 | title: '产品', |
@@ -72,6 +82,11 @@ export const physicalColumn: BasicColumn[] = [ | @@ -72,6 +82,11 @@ export const physicalColumn: BasicColumn[] = [ | ||
72 | title: '标识符', | 82 | title: '标识符', |
73 | dataIndex: FormField.IDENTIFIER, | 83 | dataIndex: FormField.IDENTIFIER, |
74 | width: 90, | 84 | width: 90, |
85 | + customRender: ({ text }: Record<'text', string>) => { | ||
86 | + return h(Tooltip, { title: text }, () => | ||
87 | + h('span', { class: 'cursor-pointer', onClick: () => handleCopy(text) }, text) | ||
88 | + ); | ||
89 | + }, | ||
75 | }, | 90 | }, |
76 | { | 91 | { |
77 | title: '数据类型', | 92 | title: '数据类型', |
@@ -2,12 +2,12 @@ | @@ -2,12 +2,12 @@ | ||
2 | <div class="p-4"> | 2 | <div class="p-4"> |
3 | <BasicTable @register="registerTable" @fetch-success="onFetchSuccess"> | 3 | <BasicTable @register="registerTable" @fetch-success="onFetchSuccess"> |
4 | <template #toolbar> | 4 | <template #toolbar> |
5 | - <a-button type="primary" @click="handleCreate"> | 5 | + <Button type="primary" @click="handleCreate"> |
6 | {{ getI18nCreateMenu }} | 6 | {{ getI18nCreateMenu }} |
7 | - </a-button> | ||
8 | - <a-button color="error" @click="handleDeleteOrBatchDelete(null)" :disabled="hasBatchDelete"> | 7 | + </Button> |
8 | + <Button type="primary" danger :disabled="getCanBatchDelete" @click="handleBatchDelete"> | ||
9 | 批量删除 | 9 | 批量删除 |
10 | - </a-button> | 10 | + </Button> |
11 | </template> | 11 | </template> |
12 | <template #action="{ record }"> | 12 | <template #action="{ record }"> |
13 | <TableAction | 13 | <TableAction |
@@ -55,23 +55,23 @@ | @@ -55,23 +55,23 @@ | ||
55 | // 导入列 属性,和搜索栏内容 | 55 | // 导入列 属性,和搜索栏内容 |
56 | import { columns } from './menu.data'; | 56 | import { columns } from './menu.data'; |
57 | import { useI18n } from '/@/hooks/web/useI18n'; | 57 | import { useI18n } from '/@/hooks/web/useI18n'; |
58 | - import { notification } from 'ant-design-vue'; | ||
59 | - import { useBatchDelete } from '/@/hooks/web/useBatchDelete'; | ||
60 | - | 58 | + import { Button, notification } from 'ant-design-vue'; |
59 | + import { useSyncConfirm } from '/@/hooks/component/useSyncConfirm'; | ||
60 | + import { isArray } from '/@/utils/is'; | ||
61 | // 自定义表格组件和属性 | 61 | // 自定义表格组件和属性 |
62 | export default defineComponent({ | 62 | export default defineComponent({ |
63 | name: 'MenuManagement', | 63 | name: 'MenuManagement', |
64 | - components: { BasicTable, MenuDrawer, TableAction }, | 64 | + components: { BasicTable, MenuDrawer, TableAction, Button }, |
65 | setup() { | 65 | setup() { |
66 | const [registerDrawer, { openDrawer }] = useDrawer(); //使用右侧弹出框 | 66 | const [registerDrawer, { openDrawer }] = useDrawer(); //使用右侧弹出框 |
67 | const { t } = useI18n(); //加载国际化 | 67 | const { t } = useI18n(); //加载国际化 |
68 | // 新增菜单 | 68 | // 新增菜单 |
69 | const getI18nCreateMenu = computed(() => t('routes.common.system.pageSystemTitleCreateMenu')); | 69 | const getI18nCreateMenu = computed(() => t('routes.common.system.pageSystemTitleCreateMenu')); |
70 | - const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete( | ||
71 | - delMenu, | ||
72 | - handleSuccess | ||
73 | - ); | ||
74 | - const [registerTable, { reload, collapseAll }] = useTable({ | 70 | + |
71 | + const [ | ||
72 | + registerTable, | ||
73 | + { reload, collapseAll, getRowSelection, getSelectRowKeys, setSelectedRowKeys }, | ||
74 | + ] = useTable({ | ||
75 | title: t('routes.common.system.pageSystemTitleMenuList'), //'菜单列表' | 75 | title: t('routes.common.system.pageSystemTitleMenuList'), //'菜单列表' |
76 | api: getMenuList, //加载数据 | 76 | api: getMenuList, //加载数据 |
77 | columns, //加载列 | 77 | columns, //加载列 |
@@ -89,9 +89,29 @@ | @@ -89,9 +89,29 @@ | ||
89 | slots: { customRender: 'action' }, | 89 | slots: { customRender: 'action' }, |
90 | fixed: 'right', | 90 | fixed: 'right', |
91 | }, | 91 | }, |
92 | - ...selectionOptions, | 92 | + rowSelection: { |
93 | + type: 'checkbox', | ||
94 | + }, | ||
93 | }); | 95 | }); |
94 | 96 | ||
97 | + const getCanBatchDelete = computed(() => { | ||
98 | + const rowSelection = getRowSelection(); | ||
99 | + return !rowSelection.selectedRowKeys?.length; | ||
100 | + }); | ||
101 | + const { createSyncConfirm } = useSyncConfirm(); | ||
102 | + const handleBatchDelete = async () => { | ||
103 | + const rowKeys = getSelectRowKeys(); | ||
104 | + try { | ||
105 | + await createSyncConfirm({ | ||
106 | + iconType: 'warning', | ||
107 | + content: '确认后所有选中的菜单将被删除', | ||
108 | + }); | ||
109 | + await handleDelete({ id: rowKeys }); | ||
110 | + setSelectedRowKeys([]); | ||
111 | + reload(); | ||
112 | + } catch (error) {} | ||
113 | + }; | ||
114 | + | ||
95 | /** | 115 | /** |
96 | * 获得删除提示框的文字 | 116 | * 获得删除提示框的文字 |
97 | */ | 117 | */ |
@@ -126,7 +146,7 @@ | @@ -126,7 +146,7 @@ | ||
126 | */ | 146 | */ |
127 | async function handleDelete(record: Recordable) { | 147 | async function handleDelete(record: Recordable) { |
128 | try { | 148 | try { |
129 | - let ids = [record.id]; | 149 | + let ids = isArray(record.id) ? record.id : [record.id]; |
130 | await delMenu(ids); | 150 | await delMenu(ids); |
131 | notification.success({ | 151 | notification.success({ |
132 | message: '成功', | 152 | message: '成功', |
@@ -161,8 +181,8 @@ | @@ -161,8 +181,8 @@ | ||
161 | handleDelete, | 181 | handleDelete, |
162 | handleSuccess, | 182 | handleSuccess, |
163 | onFetchSuccess, | 183 | onFetchSuccess, |
164 | - hasBatchDelete, | ||
165 | - handleDeleteOrBatchDelete, | 184 | + getCanBatchDelete, |
185 | + handleBatchDelete, | ||
166 | }; | 186 | }; |
167 | }, | 187 | }, |
168 | }); | 188 | }); |