From 4221095b2cb97b319477d8ed5c4471fcb998283f Mon Sep 17 00:00:00 2001 From: kaeery <3491123437@qq.com> Date: Sat, 22 Feb 2025 10:53:50 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=B4=A6=E5=8F=B7=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E3=80=91=20=E6=96=B0=E5=A2=9E#=20=E5=AD=90=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 2 +- src/components/ProDialog/index.vue | 45 ++++++ .../ProTable/components/TableColumn.vue | 42 +++++ src/components/ProTable/index.vue | 105 ++++++++++++ src/components/ProTable/interface/index.ts | 5 + src/hooks/useHandleData.ts | 18 +++ src/hooks/useSelection.ts | 24 +++ src/main.ts | 6 + src/styles/var.css | 1 + src/utils/is.ts | 4 + src/utils/util.ts | 58 ++++++- .../account-list/account-dialog.vue | 149 ++++++++++++++++++ .../organization/groupLeader-dialog copy.vue | 125 +++++++++++++++ .../organization/groupLeader-dialog.vue | 109 +++++++++++++ .../organization/organization-tree.vue | 16 +- .../account_center/sub_account/index.vue | 18 ++- .../sub_account/modules/account-list.vue | 149 +++++++++++++++++- .../sub_account/modules/organization.vue | 14 +- tailwind.config.js | 3 +- 19 files changed, 878 insertions(+), 15 deletions(-) create mode 100644 src/components/ProDialog/index.vue create mode 100644 src/components/ProTable/components/TableColumn.vue create mode 100644 src/components/ProTable/index.vue create mode 100644 src/components/ProTable/interface/index.ts create mode 100644 src/hooks/useHandleData.ts create mode 100644 src/hooks/useSelection.ts create mode 100644 src/utils/is.ts create mode 100644 src/views/account_center/sub_account/components/account-list/account-dialog.vue create mode 100644 src/views/account_center/sub_account/components/organization/groupLeader-dialog copy.vue create mode 100644 src/views/account_center/sub_account/components/organization/groupLeader-dialog.vue diff --git a/.env b/.env index 439be5a..f852037 100644 --- a/.env +++ b/.env @@ -1,2 +1,2 @@ -VITE_APP_BASE_URL = 'http://192.168.4.117:8082' +VITE_APP_BASE_URL = 'http://124.220.209.120:8082' VITE_MAP_KEY = '2SABZ-S4TWH-AMCDO-W742B-SKEOE-UWBKJ' \ No newline at end of file diff --git a/src/components/ProDialog/index.vue b/src/components/ProDialog/index.vue new file mode 100644 index 0000000..df98fe6 --- /dev/null +++ b/src/components/ProDialog/index.vue @@ -0,0 +1,45 @@ + + + + diff --git a/src/components/ProTable/components/TableColumn.vue b/src/components/ProTable/components/TableColumn.vue new file mode 100644 index 0000000..d14b4b7 --- /dev/null +++ b/src/components/ProTable/components/TableColumn.vue @@ -0,0 +1,42 @@ + + + + \ No newline at end of file diff --git a/src/components/ProTable/index.vue b/src/components/ProTable/index.vue new file mode 100644 index 0000000..33ca448 --- /dev/null +++ b/src/components/ProTable/index.vue @@ -0,0 +1,105 @@ + + + + + diff --git a/src/components/ProTable/interface/index.ts b/src/components/ProTable/interface/index.ts new file mode 100644 index 0000000..0edc930 --- /dev/null +++ b/src/components/ProTable/interface/index.ts @@ -0,0 +1,5 @@ +export type FieldNamesProps = { + label: string + value: string + children?: string +} diff --git a/src/hooks/useHandleData.ts b/src/hooks/useHandleData.ts new file mode 100644 index 0000000..0866077 --- /dev/null +++ b/src/hooks/useHandleData.ts @@ -0,0 +1,18 @@ +import { ElMessageBox } from 'element-plus' + +export type messageType = '' | 'success' | 'warning' | 'info' | 'error' +export default function useHandleData(message: string, messageType: messageType = 'warning'): Promise { + return new Promise(resolve => { + ElMessageBox.confirm(message, '温馨提示', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: messageType + }) + .then(() => { + resolve(true) + }) + .catch(() => { + resolve(false) + }) + }) +} diff --git a/src/hooks/useSelection.ts b/src/hooks/useSelection.ts new file mode 100644 index 0000000..c19c359 --- /dev/null +++ b/src/hooks/useSelection.ts @@ -0,0 +1,24 @@ +import { computed, ref } from 'vue' + +export default function useSelection(rowKey = 'id') { + const isSelected = ref(false) + const selectedList = ref([]) + + // 当前选中的所有id + const selectedListIds = computed(() => { + const ids: number | string[] = [] + selectedList.value.forEach(item => ids.push(item[rowKey])) + return ids + }) + // 多选操作 + const selectionChange = (rowArr = []) => { + isSelected.value = rowArr.length ? true : false + selectedList.value = rowArr + } + return { + isSelected, + selectedList, + selectedListIds, + selectionChange + } +} diff --git a/src/main.ts b/src/main.ts index 0f67fa7..48a25b2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -7,8 +7,14 @@ import 'virtual:svg-icons-register' import eventBus from 'vue3-eventbus' import directives from './directives' +// 表格组件 +import ProTable from '@/components/ProTable/index.vue' +import ProDialog from '@/components/ProDialog/index.vue' + const app = createApp(App) app.use(install) app.use(eventBus) app.use(directives) +app.component('ProTable', ProTable) +app.component('ProDialog', ProDialog) app.mount('#app') diff --git a/src/styles/var.css b/src/styles/var.css index c52a8e5..badb6b2 100644 --- a/src/styles/var.css +++ b/src/styles/var.css @@ -8,6 +8,7 @@ --navbar-height: 50px; --color-white: #ffffff; --color-red: #d9001b; + --color-green: #00b42a; --table-header-bg-color: #f8f8f8; --el-font-size-extra-large: 18px; --el-menu-base-level-padding: 16px; diff --git a/src/utils/is.ts b/src/utils/is.ts new file mode 100644 index 0000000..af6f6ba --- /dev/null +++ b/src/utils/is.ts @@ -0,0 +1,4 @@ +// 判断是否是数组 +export function isArray(value) { + return Array.isArray(value) +} diff --git a/src/utils/util.ts b/src/utils/util.ts index c640665..33370c5 100644 --- a/src/utils/util.ts +++ b/src/utils/util.ts @@ -1,6 +1,8 @@ import { isObject } from '@vue/shared' import { ElMessage, type messageType } from 'element-plus' import { cloneDeep } from 'lodash' +import { isArray } from './is' +import type { FieldNamesProps } from '@/components/ProTable/interface' /** * @description 添加单位 @@ -261,9 +263,9 @@ export function formatFileSize(bytes: number) { */ export function retain(value: any, n: any): string { if (n === 'null' || n === 'undefined' || n === 0) return value - let tran = Math.round(value * Math.pow(10, n)) / Math.pow(10, n) + const tran = Math.round(value * Math.pow(10, n)) / Math.pow(10, n) let tranV = tran.toString() - let newVal = tranV.indexOf('.') + const newVal = tranV.indexOf('.') if (newVal < 0) { tranV += '.' } @@ -272,3 +274,55 @@ export function retain(value: any, n: any): string { } return tranV } +/** + * @description 处理 ProTable 值为数组 || 无数据 + * @param {*} callValue 需要处理的值 + * @returns {String} + * */ +export function formatValue(callValue: any) { + // 如果当前值为数组,使用 / 拼接(根据需求自定义) + if (isArray(callValue)) return callValue.length ? callValue.join(' / ') : '--' + return callValue ?? '--' +} +/** + * + * @param {*} row 当前行数据 + * @param {*} prop 当前prop + * @returns 返回单元格值 + */ +export function handleRowAccordToProp(row: { [key: string]: any }, prop: string) { + if (!prop.includes('.')) return row[prop] ?? '--' + return row +} +/** + * 处理prop + * @param {*} prop 当前prop + */ +export function handleProp(prop: string) { + const propArr = prop.split('.') + if (propArr.length == 1) return prop + return propArr[propArr.length - 1] +} +/** + * 根据枚举列表查询当需要的数据(如果指定了 label 和 value 的 key值,会自动识别格式化) + * @param {*} callValue 当前单元格值 + * @param {*} enumData 字典列表 + */ +export function filterEnum(callValue: any, enumData?: any, fieldNames?: FieldNamesProps) { + const value = fieldNames?.value ?? 'value' + const label = fieldNames?.label ?? 'label' + const children = fieldNames?.children ?? 'children' + let filterData: { [key: string]: any } = {} + // 判断 enumData 是否为数组 + if (Array.isArray(enumData)) filterData = findItemNested(enumData, callValue, value, children) + return filterData ? filterData[label] : '--' +} + +// 递归查找 callValue 对应的 enum 值 +export function findItemNested(enumData: any, callValue: any, value: string, children: string) { + return enumData.reduce((accumulator: any, current: any) => { + if (accumulator) return accumulator + if (current[value] == callValue) return current + if (current[children]) return findItemNested(current[children], callValue, value, children) + }, null) +} diff --git a/src/views/account_center/sub_account/components/account-list/account-dialog.vue b/src/views/account_center/sub_account/components/account-list/account-dialog.vue new file mode 100644 index 0000000..2c59085 --- /dev/null +++ b/src/views/account_center/sub_account/components/account-list/account-dialog.vue @@ -0,0 +1,149 @@ + + + + + diff --git a/src/views/account_center/sub_account/components/organization/groupLeader-dialog copy.vue b/src/views/account_center/sub_account/components/organization/groupLeader-dialog copy.vue new file mode 100644 index 0000000..2508987 --- /dev/null +++ b/src/views/account_center/sub_account/components/organization/groupLeader-dialog copy.vue @@ -0,0 +1,125 @@ + + + + diff --git a/src/views/account_center/sub_account/components/organization/groupLeader-dialog.vue b/src/views/account_center/sub_account/components/organization/groupLeader-dialog.vue new file mode 100644 index 0000000..c82c5ff --- /dev/null +++ b/src/views/account_center/sub_account/components/organization/groupLeader-dialog.vue @@ -0,0 +1,109 @@ + + + + diff --git a/src/views/account_center/sub_account/components/organization/organization-tree.vue b/src/views/account_center/sub_account/components/organization/organization-tree.vue index 20b9fcb..2f40abe 100644 --- a/src/views/account_center/sub_account/components/organization/organization-tree.vue +++ b/src/views/account_center/sub_account/components/organization/organization-tree.vue @@ -2,7 +2,6 @@
- {{ currentNodeKey }}
@@ -60,6 +60,7 @@ const props = defineProps({ type: [String, Number] } }) +const emit = defineEmits(['setGroupLeader']) const defaultProps = { children: 'children', label: 'label', @@ -80,15 +81,19 @@ watch(filterText, val => { const handleNodeClick = (data: Tree) => { parent?.setSelectedNode(data) } +// 默认设置选中节点 watch( () => props.currentNodeKey, val => { if (val) { - treeRef.value?.setCurrentKey(val) + nextTick(() => { + treeRef.value?.setCurrentKey(val) + }) } } ) -const handleCommand = (command: string) => { +const handleCommand = (args: any[], data: Tree) => { + const command = args[0] switch (command) { case 'editOrganization': parent?.fetchOrganizationList() @@ -97,6 +102,7 @@ const handleCommand = (command: string) => { parent?.fetchOrganizationList() break case 'setGroupLeader': + emit('setGroupLeader', data) break } } diff --git a/src/views/account_center/sub_account/index.vue b/src/views/account_center/sub_account/index.vue index a5a028c..7672560 100644 --- a/src/views/account_center/sub_account/index.vue +++ b/src/views/account_center/sub_account/index.vue @@ -1,9 +1,9 @@ @@ -18,5 +18,17 @@ const selectedNode = ref() const setSelectedNode = (data: Tree) => { selectedNode.value = data } +watch( + () => selectedNode.value, + val => { + if (val) { + fetchTableList() + } + } +) +const accountListRef = ref>() +const fetchTableList = () => { + accountListRef.value?.fetchTableList() +} diff --git a/src/views/account_center/sub_account/modules/account-list.vue b/src/views/account_center/sub_account/modules/account-list.vue index ef00a88..ca57765 100644 --- a/src/views/account_center/sub_account/modules/account-list.vue +++ b/src/views/account_center/sub_account/modules/account-list.vue @@ -1,15 +1,162 @@ diff --git a/src/views/account_center/sub_account/modules/organization.vue b/src/views/account_center/sub_account/modules/organization.vue index 79b3424..5df8a5a 100644 --- a/src/views/account_center/sub_account/modules/organization.vue +++ b/src/views/account_center/sub_account/modules/organization.vue @@ -1,13 +1,15 @@ diff --git a/tailwind.config.js b/tailwind.config.js index 0849a2f..4db71be 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -34,7 +34,8 @@ module.exports = { fill: 'var(--el-fill-color)', 'fill-light': 'var(--el-fill-color-light)', 'fill-lighter': 'var(--el-fill-color-lighter)', - mask: 'var(--el-mask-color)' + mask: 'var(--el-mask-color)', + green: 'var(--color-green)' }, fontFamily: { sans: ['PingFang SC', 'Arial', 'Hiragino Sans GB', 'Microsoft YaHei', 'sans-serif']