From 4e344054f9d3e6c9502e16d36b15f39a4c0bf3f8 Mon Sep 17 00:00:00 2001 From: K <1175047471@qq.com> Date: Thu, 29 Feb 2024 18:07:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BA=A7=E5=93=81=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/common/index.ts | 8 ++ src/api/common/types.ts | 17 +++ src/api/product/index.ts | 41 ++++++ src/api/product/types.ts | 45 ++++++ src/router/guard/permissionGuard.ts | 6 + src/store/modules/systemEnum.ts | 57 ++++++++ src/views/product/ProductFormModal.vue | 55 ++++++++ src/views/product/data.ts | 182 +++++++++++++++++++++++++ src/views/product/index.vue | 85 ++++++++++++ 9 files changed, 496 insertions(+) create mode 100644 src/api/common/index.ts create mode 100644 src/api/common/types.ts create mode 100644 src/api/product/index.ts create mode 100644 src/api/product/types.ts create mode 100644 src/store/modules/systemEnum.ts create mode 100644 src/views/product/ProductFormModal.vue create mode 100644 src/views/product/data.ts create mode 100644 src/views/product/index.vue diff --git a/src/api/common/index.ts b/src/api/common/index.ts new file mode 100644 index 00000000..65a5ac39 --- /dev/null +++ b/src/api/common/index.ts @@ -0,0 +1,8 @@ +import type { SystemEnum } from './types' +import { defHttp } from '@/utils/http/axios' + +export function getSystemEnumAll() { + return defHttp.get({ + url: '/system/enum/getAllEnum', + }) +} diff --git a/src/api/common/types.ts b/src/api/common/types.ts new file mode 100644 index 00000000..7f506d23 --- /dev/null +++ b/src/api/common/types.ts @@ -0,0 +1,17 @@ +interface SystemEnumValue { + val: number + desc: string +} + +export type SystemEnumKeys = + | 'eProductSecurityType' + | 'eProductTopicCategory' + | 'eDataType' + | 'eProductTopicType' + | 'eNetworkProtocol' + | 'eNetworkType' + | 'eProductNodeType' + | 'eRoleAlias' + | 'eAuthType' + +export type SystemEnum = Record diff --git a/src/api/product/index.ts b/src/api/product/index.ts new file mode 100644 index 00000000..00cafee9 --- /dev/null +++ b/src/api/product/index.ts @@ -0,0 +1,41 @@ +import type { GetProductListParmas, Product } from './types' +import { defHttp } from '@/utils/http/axios' + +export function getProductList(params: GetProductListParmas) { + return defHttp.get>({ + url: '/product/page', + params, + }) +} + +export function getProductDetail(id: string) { + return defHttp.get({ + url: `/product/detail?id=${id}`, + }) +} + +export function createProduct(data: Partial) { + return defHttp.post({ + url: '/product/save', + data, + }) +} + +export function updateProduct(data: Partial) { + return defHttp.post({ + url: '/product/update', + data, + }) +} + +export function deleteProduct(id: string) { + return defHttp.post({ + url: `/product/remove?id=${id}`, + }) +} + +export function getAllProducts() { + return defHttp.get({ + url: '/product/select', + }) +} diff --git a/src/api/product/types.ts b/src/api/product/types.ts new file mode 100644 index 00000000..33424a13 --- /dev/null +++ b/src/api/product/types.ts @@ -0,0 +1,45 @@ +export interface GetProductListParmas extends PageParam { + productName?: string + networkType?: number + networkProtocol?: number + nodeType?: number + securityType?: number + dataType?: number +} + +export interface Product { + id: string + tenantId: string + uuid: string + productName: string + productDesc: string + productKey: string + productSecret: string + nodeType: number + networkType: number + networkProtocol: number + authType: number + securityType: number + dataType: number + tsl: string + isRelease: number +} + +export enum TopicType { + System = 1, + Custom = 2, +} + +export interface GetTopicListPrams { + productId?: string + topicCategory?: TopicType +} + +export interface Topic { + id: string + topic: string + topicType: number + enableScript: BooleanFlag + topicDesc: string + productId: string +} diff --git a/src/router/guard/permissionGuard.ts b/src/router/guard/permissionGuard.ts index 366bf40a..3302c6dd 100644 --- a/src/router/guard/permissionGuard.ts +++ b/src/router/guard/permissionGuard.ts @@ -6,6 +6,7 @@ import { PageEnum } from '@/enums/pageEnum' import { useUserStoreWithOut } from '@/store/modules/user' import { PAGE_NOT_FOUND_ROUTE } from '@/router/routes/basic' +import { useSystemEnumStoreWithOut } from '@/store/modules/systemEnum' // import { RootRoute } from '@/router/routes' @@ -18,6 +19,8 @@ const whitePathList: PageEnum[] = [LOGIN_PATH] export function createPermissionGuard(router: Router) { const userStore = useUserStoreWithOut() const permissionStore = usePermissionStoreWithOut() + const systemEnumStore = useSystemEnumStoreWithOut() + router.beforeEach(async (to, from, next) => { // if ( // from.path === ROOT_PATH && @@ -77,6 +80,9 @@ export function createPermissionGuard(router: Router) { return } + if (!systemEnumStore.initialized) + systemEnumStore.initialize() + // get userinfo while last fetch time is empty if (userStore.getLastUpdateTime === 0) { try { diff --git a/src/store/modules/systemEnum.ts b/src/store/modules/systemEnum.ts new file mode 100644 index 00000000..f7deab1a --- /dev/null +++ b/src/store/modules/systemEnum.ts @@ -0,0 +1,57 @@ +import { defineStore } from 'pinia' +import { ref, shallowRef } from 'vue' +import { store } from '@/store' +import { noop } from '@/utils' +import { getSystemEnumAll } from '@/api/common' +import type { SystemEnum, SystemEnumKeys } from '@/api/common/types' + +export const useSystemEnumStore = defineStore('systemEnum', () => { + const systemEnumAll = shallowRef() + + function setSystemEnumAll() { + getSystemEnumAll() + .then((res) => { + systemEnumAll.value = res + }) + .catch(noop) + } + + function getSystemEnumLabel(enumType: SystemEnumKeys, value: number) { + if (!systemEnumAll.value) + return + + const ret = systemEnumAll.value[enumType].find(item => item.val === value) + return ret && ret.desc + } + + function getSystemEnums(enumType: SystemEnumKeys, options?: { labelField: string, valueField: string }) { + if (!systemEnumAll.value) + return [] + + const enums = systemEnumAll.value[enumType] || [] + const { labelField, valueField } = options || { labelField: 'label', valueField: 'value' } + return enums.map((item) => { + return { + [labelField]: item.desc, + [valueField]: item.val, + } + }) + } + + const initialized = ref(false) + function initialize() { + initialized.value = true + setSystemEnumAll() + } + + return { + initialized, + initialize, + getSystemEnumLabel, + getSystemEnums, + } +}) + +export function useSystemEnumStoreWithOut() { + return useSystemEnumStore(store) +} diff --git a/src/views/product/ProductFormModal.vue b/src/views/product/ProductFormModal.vue new file mode 100644 index 00000000..ee7f2c13 --- /dev/null +++ b/src/views/product/ProductFormModal.vue @@ -0,0 +1,55 @@ + + + diff --git a/src/views/product/data.ts b/src/views/product/data.ts new file mode 100644 index 00000000..ca6a6fcc --- /dev/null +++ b/src/views/product/data.ts @@ -0,0 +1,182 @@ +import type { Ref } from 'vue' +import type { BasicColumn, FormSchema } from '@/components/Table' +import { useSystemEnumStoreWithOut } from '@/store/modules/systemEnum' + +const { getSystemEnumLabel, getSystemEnums } = useSystemEnumStoreWithOut() + +export const columns: BasicColumn[] = [ + { + title: '产品名称', + dataIndex: 'productName', + }, + { + title: '产品标识', + dataIndex: 'productKey', + }, + { + title: '节点类型', + dataIndex: 'nodeType', + customRender: ({ value }) => getSystemEnumLabel('eProductNodeType', value), + }, + { + title: '联网方式', + dataIndex: 'networkType', + customRender: ({ value }) => getSystemEnumLabel('eNetworkType', value), + }, + { + title: '鉴权方式', + dataIndex: 'authType', + customRender: ({ value }) => getSystemEnumLabel('eAuthType', value), + }, + { + title: '安全类型', + dataIndex: 'securityType', + customRender: ({ value }) => getSystemEnumLabel('eProductSecurityType', value), + }, + { + title: '通信协议', + dataIndex: 'networkProtocol', + customRender: ({ value }) => getSystemEnumLabel('eNetworkProtocol', value), + }, + { + title: '数据格式', + dataIndex: 'dataType', + customRender: ({ value }) => getSystemEnumLabel('eDataType', value), + }, + { + title: '创建时间', + dataIndex: 'createTime', + width: 200, + }, +] + +export const searchFormSchemas: FormSchema[] = [ + { + label: '产品名称', + field: 'productName', + component: 'Input', + colProps: { span: 6 }, + }, + { + label: '联网方式', + field: 'networkType', + component: 'Select', + componentProps: { + options: getSystemEnums('eNetworkType'), + }, + colProps: { span: 6 }, + }, + { + label: '通信协议', + field: 'networkProtocol', + component: 'Select', + componentProps: { + options: getSystemEnums('eNetworkProtocol'), + }, + colProps: { span: 6 }, + }, + { + label: '节点类型', + field: 'nodeType', + component: 'Select', + componentProps: { + options: getSystemEnums('eProductNodeType'), + }, + colProps: { span: 6 }, + }, + { + label: '安全类型', + field: 'securityType', + component: 'Select', + componentProps: { + options: getSystemEnums('eProductSecurityType'), + }, + colProps: { span: 6 }, + }, + { + label: '数据格式', + field: 'dataType', + component: 'Select', + componentProps: { + options: getSystemEnums('eDataType'), + }, + colProps: { span: 6 }, + }, +] + +export function getFormSchema(isUpdate: Ref): FormSchema[] { + return [ + { + field: 'id', + show: false, + component: 'Input', + }, + { + label: '产品名称', + field: 'productName', + required: true, + component: 'Input', + }, + { + label: '联网方式', + field: 'networkType', + component: 'Select', + componentProps: { + options: getSystemEnums('eNetworkType'), + }, + }, + { + label: '通信协议', + field: 'networkProtocol', + component: 'Select', + componentProps: { + options: getSystemEnums('eNetworkProtocol'), + }, + ifShow: () => !isUpdate.value, + }, + { + label: '节点类型', + field: 'nodeType', + required: true, + component: 'Select', + componentProps: { + options: getSystemEnums('eProductNodeType'), + }, + ifShow: () => !isUpdate.value, + }, + { + label: '安全类型', + field: 'securityType', + component: 'Select', + componentProps: { + options: getSystemEnums('eProductSecurityType'), + }, + ifShow: () => !isUpdate.value, + }, + { + label: '鉴权方式', + field: 'authType', + required: true, + component: 'Select', + componentProps: { + options: getSystemEnums('eAuthType'), + }, + ifShow: () => !isUpdate.value, + }, + { + label: '数据格式', + field: 'dataType', + required: true, + component: 'Select', + componentProps: { + options: getSystemEnums('eDataType'), + }, + ifShow: () => !isUpdate.value, + }, + { + label: '产品描述', + field: 'productDesc', + component: 'InputTextArea', + }, + ] +} diff --git a/src/views/product/index.vue b/src/views/product/index.vue new file mode 100644 index 00000000..e38bb836 --- /dev/null +++ b/src/views/product/index.vue @@ -0,0 +1,85 @@ + + +