From f473124ce815146a0e6b0c2cdbaaf2716d16f8d4 Mon Sep 17 00:00:00 2001 From: XieYongHong <18010623010@163.com> Date: Mon, 30 Oct 2023 16:42:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20bug#19215=E3=80=8119214=E3=80=8119213?= =?UTF-8?q?=E3=80=8119183=E3=80=8119060=E3=80=8119090=E3=80=8119167?= =?UTF-8?q?=E3=80=8119090?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 优化物模型配置按钮样式 * fix: bug#18263 * fix: 优化iframe中hash地址 * fix: bug#19132 * fix: bug#19071 * Dev bug (#217) * fix: bug#19215、19214、19213、19183 * fix: bug#19060、19090 * fix: bug#19167 * fix: bug#19080 * fix: bug#19181 * fix: bug#19060、19090 * fix: bug#19181 * fix: iframe组件优化没有参数时,url格式 --- .npmrc | 2 +- README.md | 12 ++ package.json | 2 +- src/App.vue | 6 +- src/components/FRuleEditor/Editor/index.vue | 62 +++--- src/components/FRuleEditor/index.vue | 45 +++- src/components/Layout/BasicLayoutPage.vue | 17 +- src/components/PermissionButton/index.vue | 4 +- src/hook/index.ts | 1 + src/hook/useRequest.ts | 92 +++++++++ src/main.ts | 2 +- src/store/menu.ts | 14 +- src/store/system.ts | 2 +- src/style.less | 6 +- src/utils/menu.ts | 195 +----------------- src/utils/request.ts | 6 +- src/utils/utils.ts | 10 +- .../Collector/Point/Scan/Table.vue | 2 +- .../DataCollect/Collector/Tree/Save/index.vue | 8 +- src/views/DataCollect/Collector/data.ts | 2 +- src/views/account/Center/index.vue | 17 +- src/views/device/DashBoard/index.vue | 10 +- .../Instance/Detail/ChildDevice/index.vue | 146 +++++-------- .../Instance/Detail/Diagnose/Status/index.tsx | 6 +- .../Detail/Function/components/Simple.vue | 4 +- .../Detail/Running/Property/Detail/Charts.vue | 3 +- .../components/BindParentDevice/index.vue | 2 +- .../components/EditTable/PatchMapping.vue | 6 +- .../Detail/components/EditTable/index.vue | 17 +- .../Instance/Detail/components/MSelect.vue | 3 +- .../Detail/DeviceAccess/accessModal.vue | 4 +- src/views/device/Product/Save/index.vue | 5 +- src/views/device/Product/index.vue | 7 +- .../device/components/Metadata/Base/Base.vue | 61 +++--- .../components/Metadata/Base/columns.tsx | 13 +- .../Metadata/Base/components/DataType.vue | 24 ++- .../Base/components/Events/ConfigParams.vue | 17 +- .../Base/components/Function/InputParams.vue | 10 +- .../Base/components/Function/OutputParams.vue | 21 +- .../Metadata/Base/components/ModelButton.vue | 2 +- .../Properties/Metrics/ValueItem.vue | 4 +- .../components/Properties/OtherSetting.vue | 17 +- .../Metadata/Base/components/Source.vue | 6 +- .../device/components/Metadata/Cat/index.vue | 2 +- .../components/Metadata/Import/index.vue | 56 ++--- src/views/iframe/index.vue | 31 ++- src/views/init-home/InitData/index.vue | 7 +- src/views/link/Certificate/Detail/index.vue | 166 ++++++--------- .../link/DashBoard/components/Network.vue | 16 +- src/views/link/Type/Detail/index.vue | 2 +- .../media/Device/Channel/Share/index.vue | 2 +- .../notice/Config/Detail/doc/Webhook.tsx | 8 +- src/views/notice/Config/Detail/index.vue | 10 +- src/views/notice/const.ts | 4 +- .../rule-engine/Alarm/Config/Io/index.vue | 2 +- .../rule-engine/Scene/Save/Device/Product.vue | 8 +- .../Scene/Save/action/Device/Product.vue | 9 +- .../action/Device/actions/FunctionItem.vue | 8 +- .../action/Device/actions/WriteProperty.vue | 17 +- .../Scene/Save/action/ListItem/Item.vue | 2 +- .../system/Apply/Save/components/EditForm.vue | 20 +- .../system/Apply/componenets/ThirdMenu.vue | 150 ++++++++++++++ src/views/system/Apply/componenets/util.ts | 27 +++ src/views/system/Apply/index.vue | 10 +- src/views/system/Menu/Detail/BasicInfo.vue | 19 +- src/views/system/Menu/Setting/index.vue | 4 +- src/views/system/Menu/index.vue | 26 +-- .../NoticeRule/components/Item/index.vue | 2 + .../Permission/components/EditDialog.vue | 2 +- .../Platforms/Api/components/ApiTest.vue | 2 +- vite.config.ts | 2 +- yarn.lock | 8 +- 72 files changed, 858 insertions(+), 659 deletions(-) create mode 100644 src/hook/index.ts create mode 100644 src/hook/useRequest.ts create mode 100644 src/views/system/Apply/componenets/ThirdMenu.vue create mode 100644 src/views/system/Apply/componenets/util.ts diff --git a/.npmrc b/.npmrc index dfe2ca70..f408e702 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ always-auth=true -registry=http://registry.jetlinks.cn/ \ No newline at end of file +registry=https://registry.npmjs.org/ diff --git a/README.md b/README.md index d9709551..ee607b6f 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,18 @@ yarn dev:force 此处可以更改系统名称、主题色、系统logo、浏览器页签等 +#### 主题色 + +```javascript +// src/App.vue + +ConfigProvider.config({ + theme: { + primaryColor: "#315efb" + } +}) +``` + #### 2.默认配置 在代码根目录找到`config\config.ts`文件 diff --git a/package.json b/package.json index 85968eac..6976a7c2 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "event-source-polyfill": "^1.0.31", "global": "^4.4.0", "jetlinks-store": "^0.0.3", - "jetlinks-ui-components": "^1.0.33", + "jetlinks-ui-components": "^1.0.34-4", "js-cookie": "^3.0.1", "jsencrypt": "^3.3.2", "less": "^4.1.3", diff --git a/src/App.vue b/src/App.vue index 8c6581c2..0c14af16 100644 --- a/src/App.vue +++ b/src/App.vue @@ -15,7 +15,11 @@ const system = useSystem(); const {configInfo} = storeToRefs(system); system.setDocumentTitle() - +ConfigProvider.config({ + theme: { + primaryColor: "#315efb" + } +}) \ No newline at end of file + diff --git a/src/hook/index.ts b/src/hook/index.ts new file mode 100644 index 00000000..f222b03e --- /dev/null +++ b/src/hook/index.ts @@ -0,0 +1 @@ +export * from './useRequest' diff --git a/src/hook/useRequest.ts b/src/hook/useRequest.ts new file mode 100644 index 00000000..6d2d9c03 --- /dev/null +++ b/src/hook/useRequest.ts @@ -0,0 +1,92 @@ +import {onUnmounted, ref} from 'vue' +import type { Ref } from 'vue' +import {isFunction, get, isArray} from 'lodash-es' +import type { AxiosResponseRewrite } from '@/utils/request' + +interface RequestOptions { + immediate: boolean + /** + * 成功回调 + * @param data + * @returns + */ + onSuccess: (data: AxiosResponseRewrite) => S | void + /** + * 返回参数处理 + * @returns + */ + formatName: string | [string] + onError: (e: any) => void + + defaultParams: S | any | any[] + + handleResponse: (data: any) => any +} + +const defaultOptions: any = { + immediate: true, + formatName: 'result' +} + +type Run = (...args: any[]) => void + +export const useRequest = ( + request: (...args: any[]) => Promise>, + options: Partial> = defaultOptions, +): { + data: Ref, + loading: Ref, + run: Run +} => { + const data = ref() + const loading = ref(false) + const _options = { + ...defaultOptions, + ...options + } + + async function run(...arg: any[]) { + if (request && isFunction(request)) { + loading.value = true + try { + // @ts-ignore + const resp = await request.apply(this, arg) + + loading.value = false + + if (resp?.success) { + const successData = await _options.onSuccess?.(resp) + data.value = successData || get(resp, _options.formatName!) + // console.log(data.value) + } else { + _options.onError?.(resp) + } + } catch (e) { + loading.value = false + _options.onError?.(e) + } + } + } + + if (_options.immediate) { // 主动触发 + if (_options.defaultParams) { + isArray(_options.defaultParams) ? run(..._options.defaultParams) : run(_options.defaultParams) + } else { + run() + } + } + + onUnmounted(() => { + // 销毁时,撤销该请求 + if (request && isFunction(request)) { + + } + // request() + }) + + return { + data, + loading, + run + } +} diff --git a/src/main.ts b/src/main.ts index 4cc48040..4f371d2c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,7 +4,7 @@ import store from './store' import components from './components' import router from './router' import './style.less' - +import 'ant-design-vue/dist/antd.variable.min.css' import dayjs from 'dayjs'; import 'dayjs/locale/zh-cn'; dayjs.locale('zh-cn'); diff --git a/src/store/menu.ts b/src/store/menu.ts index ab33fa91..846f4695 100644 --- a/src/store/menu.ts +++ b/src/store/menu.ts @@ -24,12 +24,12 @@ const defaultOwnParams = [ termType: 'eq', value: 'iot' }, - { - column: 'owner', - termType: 'isnull', - value: '1', - type: 'or' - } + // { + // column: 'owner', + // termType: 'isnull', + // value: '1', + // type: 'or' + // } ] } ] @@ -129,4 +129,4 @@ export const useMenuStore = defineStore({ }) } } -}) \ No newline at end of file +}) diff --git a/src/store/system.ts b/src/store/system.ts index 97186d67..204a4298 100644 --- a/src/store/system.ts +++ b/src/store/system.ts @@ -89,4 +89,4 @@ export const useSystem = defineStore('system', { } } } -}) \ No newline at end of file +}) diff --git a/src/style.less b/src/style.less index b119250d..bfd73195 100644 --- a/src/style.less +++ b/src/style.less @@ -30,9 +30,9 @@ body { .ant-pro-top-nav-header { .ant-menu-item { - padding: 0 10px !important; - &:not(:first-child) { - margin-left: 8px !important; + padding: 0 14px !important; + &:first-child { + padding: 0 10px !important; } } } diff --git a/src/utils/menu.ts b/src/utils/menu.ts index 53e4ebe4..1d11aabd 100644 --- a/src/utils/menu.ts +++ b/src/utils/menu.ts @@ -1,6 +1,7 @@ import { BlankLayoutPage, BasicLayoutPage } from 'components/Layout' import { isNoCommunity } from '@/utils/utils' import Iframe from '../views/iframe/index.vue' +import { shallowRef, defineAsyncComponent } from 'vue' const pagesComponent = import.meta.glob('../views/**/*.vue'); @@ -155,192 +156,6 @@ const extraRouteObj = { } }; -// -// const resolveComponent = (name: any) => { -// const importPage = pagesComponent[`../views/${name}/index.vue`]; -// console.log(importPage) -// if (!importPage) { -// return undefined -// } else { -// const res = () => importPage() -// return res -// } -// //@ts-ignore -// } -// -// const findChildrenRoute = (code: string, url: string, routes: any[] = []): MenuItem[] => { -// if (extraRouteObj[code]) { -// const extraRoutes = extraRouteObj[code].children.map((route: MenuItem) => { -// return { -// url: `${url}/${route.code}`, -// code: `${code}/${route.code}`, -// name: route.name, -// isShow: false -// } -// }) -// return [...routes, ...extraRoutes] -// } -// return routes -// } -// -// const findDetailRouteItem = (code: string, url: string): Partial | null => { -// const detailComponent = resolveComponent(`${code}/Detail`) -// if (detailComponent) { -// return { -// url: `${url}/detail/:id`, -// code: `${code}/Detail`, -// component: detailComponent, -// name: '详情信息', -// isShow: false -// } -// } -// return null -// } -// -// const findDetailRoutes = (routes: any[]): any[] => { -// const newRoutes: any[] = [] -// routes.forEach((route: any) => { -// newRoutes.push(route) -// const detail = findDetailRouteItem(route.code, route.url) -// if (detail) { -// newRoutes.push(detail) -// } -// }) -// return newRoutes -// } -// -// const filterMenus = ['device/DashBoard'] -// export const filterCommunityMenus = (menuData: any[]) => { -// return menuData.filter(item => { -// if (item.children) { -// item.children = filterCommunityMenus(item.children) -// } -// return !filterMenus.includes(item.code) -// }) -// } -// -// export const findCodeRoute = (asyncRouterMap: any[]) => { -// const routeMeta = {} -// -// function getDetail(code: string, url: string) { -// const detail = findDetailRouteItem(code, url) -// if (!detail) return -// -// routeMeta[(detail as MenuItem).code] = { -// path: detail.url, -// title: detail.name, -// parentName: code, -// buttons: detail.buttons?.map((b: any) => b.id) || [] -// } -// } -// -// function findChildren(data: any[], code: string = '') { -// data.forEach(route => { -// routeMeta[route.code] = { -// path: route.url || route.path, -// title: route.meta?.title || route.name, -// parentName: code, -// buttons: route.buttons?.map((b: any) => b.id) || [] -// } -// const otherRoutes = extraRouteObj[route.code] -// -// if (otherRoutes) { -// otherRoutes.children.map((item: any) => { -// const _code = `${route.code}/${item.code}` -// const url = `${route.url}/${item.code}` -// routeMeta[_code] = { -// path: `${route.url}/${item.code}`, -// title: item.name, -// parentName: route.code, -// buttons: item.buttons?.map((b: any) => b.id) || [] -// } -// getDetail(_code, url) -// }) -// } -// const _code = route.appId ? `/${route.appId}${route.url}` : route.code -// if (!route.appId) { -// getDetail(_code, route.url) -// } else { -// routeMeta[_code] = { -// path: `/${route.appId}${route.url}`, -// title: route.name, -// parentName: code, -// buttons: [] -// } -// } -// if (route.children) { -// findChildren(route.children, _code) -// } -// }) -// } -// -// findChildren(asyncRouterMap) -// -// return routeMeta -// } -// -// export function filterAsyncRouter(asyncRouterMap: any, parentCode = '', level = 1): { menusData: any, silderMenus: any } { -// const _asyncRouterMap = cloneDeep(asyncRouterMap) -// const menusData: any[] = [] -// const silderMenus: any[] = [] -// _asyncRouterMap.forEach((route: any) => { -// const hasAppId = route.appId -// const _route: any = { -// path: hasAppId ? `/${route.appId}${route.url}` : `${route.url}`, -// name: hasAppId ? `/${route.appId}${route.url}` : route.code, -// url: hasAppId ? `/${route.appId}${route.url}` : route.url, -// meta: { -// icon: route.icon, -// title: route.name, -// hideInMenu: route.isShow === false, -// buttons: route.buttons?.map((b: any) => b.id) || [], -// isApp: hasAppId, -// }, -// } -// -// const silder = { ..._route } -// // 查看是否有隐藏子路由 -// route.children = findChildrenRoute(route.code, route.url, route.children) -// route.children = findDetailRoutes(route.children) -// if (route.children && route.children.length) { -// // TODO 查看是否具有详情页 -// const { menusData: _menusData, silderMenus: _silderMenus } = filterAsyncRouter(route.children, `${parentCode}/${route.code}`, level + 1) -// _route.children = _menusData -// silder.children = _silderMenus -// const showChildren = _route.children.some((r: any) => !r.meta.hideInMenu) -// -// if (showChildren && _route.children.length) { -// _route.component = level === 1 ? BasicLayoutPage : BlankLayoutPage -// _route.redirect = _route.children[0].url -// } else { -// const myComponent = resolveComponent(route.code) -// // _route.component = myComponent ? myComponent : BlankLayoutPage; -// if (!!myComponent) { -// _route.component = myComponent; -// _route.children.map((r: any) => menusData.push(r)) -// delete _route.children -// } else { -// _route.component = BlankLayoutPage -// } -// } -// } else { -// if (hasAppId) { -// _route.component = route.component || resolveComponent('iframe') -// } else { -// _route.component = route.component || resolveComponent(route.code) || BlankLayoutPage -// } -// } -// menusData.push(_route) -// silderMenus.push(silder) -// }) -// return { -// menusData, -// silderMenus, -// } -// } - -import { shallowRef } from 'vue' - type Buttons = Array<{ id: string }> const hasAppID = (item: { appId?: string, url?: string }): { isApp: boolean, appUrl: string } => { @@ -367,6 +182,12 @@ const handleMeta = (item: MenuItem, isApp: boolean) => { const findComponents = (code: string, level: number, isApp: boolean, components: any) => { const myComponents = components[code] if (level === 1) { // BasicLayoutPage + if (myComponents) { + return h(BasicLayoutPage, {}, () => [h(defineAsyncComponent(() => myComponents()), {})]) + } + if (isApp) { + return h(BasicLayoutPage, {}, () => [h(Iframe, {})]) + } return myComponents ? () => myComponents() : BasicLayoutPage } else if (isApp){ // iframe return Iframe @@ -529,4 +350,4 @@ export const handleAuthMenu = (menuData: any[], cb: (code: any, buttons: any[]) } }) } -} \ No newline at end of file +} diff --git a/src/utils/request.ts b/src/utils/request.ts index 197db378..e2002cf7 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -6,7 +6,7 @@ import { LoginPath } from '@/router/menu' import { cleanToken, getToken, LocalStore } from '@/utils/comm' import type { AxiosInstance, AxiosResponse } from 'axios' -interface AxiosResponseRewrite extends AxiosResponse { +export interface AxiosResponseRewrite extends AxiosResponse { result: T success: boolean } @@ -150,7 +150,7 @@ const showNotification = (message: string, description: string, key?: string, sh * @returns {Promise} */ const errorHandler = (error: any) => { - + if (error.response) { const data = error.response.data const status = error.response.status @@ -257,4 +257,4 @@ export default { remove, getStream, postStream -} \ No newline at end of file +} diff --git a/src/utils/utils.ts b/src/utils/utils.ts index c151afec..e313716c 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -71,8 +71,8 @@ export const isNoCommunity = !(localStorage.getItem(SystemConst.VERSION_CODE) == /** * 生成随机数 - * @param length - * @returns + * @param length + * @returns */ export const randomString = (length?: number) => { const tempLength = length || 32; @@ -87,8 +87,8 @@ export const randomString = (length?: number) => { /** * 时间戳转时分秒文本 - * @param time - * @returns + * @param time + * @returns */ export const timestampFormat = (time: number) => { let hour = 0; @@ -182,4 +182,4 @@ export const EventEmitter = { }) return this } -} \ No newline at end of file +} diff --git a/src/views/DataCollect/Collector/Point/Scan/Table.vue b/src/views/DataCollect/Collector/Point/Scan/Table.vue index b2826b2f..63688e69 100644 --- a/src/views/DataCollect/Collector/Point/Scan/Table.vue +++ b/src/views/DataCollect/Collector/Point/Scan/Table.vue @@ -5,6 +5,7 @@ :dataSource="modelRef.dataSource" :columns="FormTableColumns" :scroll="{ y: 580 }" + :pagination="false" >