From 96c6b69aef83971be80b07b7907e60c19a8502dd Mon Sep 17 00:00:00 2001 From: xieyonghong <18010623010@163.com> Date: Thu, 23 Mar 2023 18:41:52 +0800 Subject: [PATCH] fix: bug#10782 --- src/utils/comm.ts | 25 +++++++++++ src/utils/request.ts | 45 +++++++------------ src/views/device/Product/Detail/index.vue | 4 +- .../Save/action/ListItem/FilterCondition.vue | 19 ++++++-- .../Save/action/ListItem/FilterGroup.vue | 2 +- .../Save/components/Terms/ParamsItem.vue | 28 ++++++++---- .../Scene/Save/components/Terms/TermsItem.vue | 2 +- src/views/rule-engine/Scene/index.vue | 2 +- vite.config.ts | 2 +- yarn.lock | 4 +- 10 files changed, 83 insertions(+), 50 deletions(-) diff --git a/src/utils/comm.ts b/src/utils/comm.ts index 85f9273f..50d71456 100644 --- a/src/utils/comm.ts +++ b/src/utils/comm.ts @@ -108,4 +108,29 @@ export const onlyMessage = (msg: string, type: 'success' | 'error' | 'warning' = content: msg, key: type }) +} + +export interface SearchItemData { + column: any; + value: any; + termType: string; + type?: string; +} + +export const handleParamsToString = (terms:SearchItemData[] = []) => { + const _terms: any[] = [ + { terms: [null,null,null]}, + { terms: [null,null,null]} + ] + let termsIndex = 0 + let termsStar = 0 + terms.forEach((item, index) => { + if (index > 2) { + termsIndex = 1 + termsStar = 4 + } + _terms[termsIndex].terms[index - termsStar ] = item + }) + + return JSON.stringify({ terms: _terms}) } \ No newline at end of file diff --git a/src/utils/request.ts b/src/utils/request.ts index 5c260845..2397c36e 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -118,6 +118,16 @@ export const postStream = function(url: string, data={}, params = {}) { }) } +const showNotification = ( message: string, description: string, key?: string, show: boolean = true ) => { + if (show) { + Notification.error({ + key, + message, + description + }) + } +} + /** * 异常拦截处理器 * @param {Object} error @@ -128,44 +138,19 @@ const errorHandler = (error: any) => { const data = error.response.data const status = error.response.status if (status === 403) { - Notification.error({ - key: '403', - message: 'Forbidden', - description: (data.message + '').substr(0, 90) - }) - - setTimeout(() => { - router.push({ - name: 'Exception403' - }) - }, 0) + showNotification( 'Forbidden', (data.message + '').substr(0, 90), '403') } else if (status === 500) { - Notification.error({ - key: '500', - message: 'Server Side Error', - description: (data.message + '').substr(0, 90) - }) + showNotification( 'Server Side Error', (data.message + '').substr(0, 90), '500') } else if (status === 400) { - Notification.error({ - key: '400', - message: 'Request Error', - description: (data.message + '').substr(0, 90) - }) + showNotification( 'Request Error', (data.message + '').substr(0, 90), '400') } else if (status === 401) { - Notification.error({ - key: '401', - message: 'Unauthorized', - description: '用户未登录' - }) + showNotification( 'Unauthorized', '用户未登录', '401') setTimeout(() => { location.href = `/#${LoginPath}` }, 0) } } else if (error.response === undefined) { - Notification.error({ - message: error.message, - description: (error.stack + '').substr(0, 90) - }) + showNotification( error.message, (error.stack + '').substr(0, 90), undefined) } return Promise.reject(error) } diff --git a/src/views/device/Product/Detail/index.vue b/src/views/device/Product/Detail/index.vue index cd9630d1..4b1a3fa9 100644 --- a/src/views/device/Product/Detail/index.vue +++ b/src/views/device/Product/Detail/index.vue @@ -111,7 +111,7 @@ import { getProtocolDetail, } from '@/api/device/product'; import { message } from 'jetlinks-ui-components'; -import { getImage } from '@/utils/comm'; +import { getImage, handleParamsToString } from '@/utils/comm' import encodeQuery from '@/utils/encodeQuery'; import { useMenuStore } from '@/store/menu'; @@ -286,7 +286,7 @@ const jumpDevice = () => { {}, { target: 'device-instance', - q: JSON.stringify({ terms: [{ terms: [{ searchParams }] }] }), + q: handleParamsToString([searchParams]), }, ); }; diff --git a/src/views/rule-engine/Scene/Save/action/ListItem/FilterCondition.vue b/src/views/rule-engine/Scene/Save/action/ListItem/FilterCondition.vue index 3fb84629..2d23a412 100644 --- a/src/views/rule-engine/Scene/Save/action/ListItem/FilterCondition.vue +++ b/src/views/rule-engine/Scene/Save/action/ListItem/FilterCondition.vue @@ -188,11 +188,18 @@ const handOptionByColumn = (option: any) => { } } -watchEffect(() => { - if (!props.value.error && props.value.column) { // 新增不查找option +watch(() => [columnOptions.value, paramsValue.column], () => { + if (paramsValue.column) { const option = getOption(columnOptions.value, paramsValue.column, 'id') - if (option) { + if (option && Object.keys(option).length) { handOptionByColumn(option) + if (props.value.error) { + emit('update:value', { + ...props.value, + error: false + }) + formItemContext.onFieldChange() + } } else { emit('update:value', { ...props.value, @@ -203,6 +210,12 @@ watchEffect(() => { } }) +watchEffect(() => { + if (!props.value.error && props.value.column) { // 新增不查找option + + } +}) + const showDouble = computed(() => { const isRange = paramsValue.termType ? arrayParamsKey.includes(paramsValue.termType) : false return isRange diff --git a/src/views/rule-engine/Scene/Save/action/ListItem/FilterGroup.vue b/src/views/rule-engine/Scene/Save/action/ListItem/FilterGroup.vue index 4700f49b..a0613705 100644 --- a/src/views/rule-engine/Scene/Save/action/ListItem/FilterGroup.vue +++ b/src/views/rule-engine/Scene/Save/action/ListItem/FilterGroup.vue @@ -213,7 +213,7 @@ const rules = [ return Promise.reject(new Error('请选择操作符')) } - if (v.value === undefined) { + if (v.value.value === undefined) { return Promise.reject(new Error('请选择或输入参数值')) } else { if ( diff --git a/src/views/rule-engine/Scene/Save/components/Terms/ParamsItem.vue b/src/views/rule-engine/Scene/Save/components/Terms/ParamsItem.vue index 9092feed..8fae8ebf 100644 --- a/src/views/rule-engine/Scene/Save/components/Terms/ParamsItem.vue +++ b/src/views/rule-engine/Scene/Save/components/Terms/ParamsItem.vue @@ -81,6 +81,7 @@ import { ContextKey } from './util' import { useSceneStore } from 'store/scene' import { storeToRefs } from 'pinia'; import { Form } from 'jetlinks-ui-components' +import { pick } from 'lodash-es' const sceneStore = useSceneStore() const { data: formModel } = storeToRefs(sceneStore) @@ -187,11 +188,18 @@ const handOptionByColumn = (option: any) => { } } -watchEffect(() => { - if (!props.value.error && props.value.column) { // 新增不查找option +watch(() => [columnOptions.value, paramsValue.column], () => { + if (paramsValue.column) { const option = getOption(columnOptions.value, paramsValue.column, 'column') - if (option) { + if (option && Object.keys(option).length) { handOptionByColumn(option) + if (props.value.error) { + emit('update:value', { + ...props.value, + error: false + }) + formItemContext.onFieldChange() + } } else { emit('update:value', { ...props.value, @@ -200,7 +208,7 @@ watchEffect(() => { formItemContext.onFieldChange() } } -}) +}, { immediate: true, deep: true }) const showDouble = computed(() => { const isRange = paramsValue.termType ? arrayParamsKey.includes(paramsValue.termType) : false @@ -225,15 +233,17 @@ const mouseout = () => { } const columnSelect = (option: any) => { - paramsValue.termType = 'eq' + const termTypes = option.termTypes + paramsValue.termType = termTypes?.length ? termTypes[0].id : 'eq' paramsValue.value = { source: tabsOptions.value[0].key, value: undefined } - emit('update:value', { ...paramsValue }) - formItemContext.onFieldChange() + handOptionByColumn(option) formModel.value.options!.when[props.whenName].terms[props.termsName].terms[props.name][0] = option.name formModel.value.options!.when[props.whenName].terms[props.termsName].terms[props.name][1] = paramsValue.termType + emit('update:value', { ...paramsValue }) + formItemContext.onFieldChange() } const termsTypeSelect = (e: { key: string, name: string }) => { @@ -242,9 +252,9 @@ const termsTypeSelect = (e: { key: string, name: string }) => { source: tabsOptions.value[0].key, value: value } + formModel.value.options!.when[props.whenName].terms[props.termsName].terms[props.name][1] = e.name emit('update:value', { ...paramsValue }) formItemContext.onFieldChange() - formModel.value.options!.when[props.whenName].terms[props.termsName].terms[props.name][1] = e.name } const valueSelect = (_: any, label: string, labelObj: Record) => { @@ -277,7 +287,7 @@ const onDelete = () => { } nextTick(() => { - Object.assign(paramsValue, props.value) + Object.assign(paramsValue, pick(props.value, ['column', 'options', 'termType', 'terms', 'type', 'value'])) }) diff --git a/src/views/rule-engine/Scene/Save/components/Terms/TermsItem.vue b/src/views/rule-engine/Scene/Save/components/Terms/TermsItem.vue index 24912f54..d3008581 100644 --- a/src/views/rule-engine/Scene/Save/components/Terms/TermsItem.vue +++ b/src/views/rule-engine/Scene/Save/components/Terms/TermsItem.vue @@ -120,7 +120,7 @@ const rules = [ return Promise.reject(new Error('请选择操作符')); } - if (v.value === undefined) { + if (!v.value?.value) { return Promise.reject(new Error('请选择或输入参数值')); } else { if ( diff --git a/src/views/rule-engine/Scene/index.vue b/src/views/rule-engine/Scene/index.vue index 92f38c15..775ba754 100644 --- a/src/views/rule-engine/Scene/index.vue +++ b/src/views/rule-engine/Scene/index.vue @@ -311,7 +311,7 @@ const getActions = ( }, icon: 'LikeOutlined', popConfirm: { - title: '', + title: '确认手动触发?', onConfirm: async () => { const resp = await _execute(data.id); if (resp.status === 200) { diff --git a/vite.config.ts b/vite.config.ts index 3686a5bf..a55d7960 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -92,7 +92,7 @@ export default defineConfig(({ mode}) => { [env.VITE_APP_BASE_API]: { // target: 'http://192.168.33.22:8800', // target: 'http://192.168.32.244:8881', - // target: 'http://120.77.179.54:8844', // 120测试 + // target: 'http://120.77.179.54:8844', // 120测试 target: 'http://192.168.33.46:8844', // 本地开发环境 ws: 'ws://192.168.33.46:8844', changeOrigin: true, diff --git a/yarn.lock b/yarn.lock index 0e53dbfb..c10837ab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3700,8 +3700,8 @@ jetlinks-store@^0.0.3: jetlinks-ui-components@^1.0.5: version "1.0.5" - resolved "http://47.108.170.157:9013/jetlinks-ui-components/-/jetlinks-ui-components-1.0.5.tgz#f2e62df4054e513df39e3355592d95e356438328" - integrity sha512-vfQ8g8nEJueDkHCVcg9WeWDDjnPklyigbobB1CQArfHLd5O4x6vLFWvF69k0yqytCvIOXB13CzhLtMnv68pC5w== + resolved "http://47.108.170.157:9013/jetlinks-ui-components/-/jetlinks-ui-components-1.0.5.tgz#147926716787ac22464b5ce81180ce43a93e40cc" + integrity sha512-guypzc4QurKHfVoDrCo28Bx721kbTx8/W9r8jROWINI0J11ZTRi5bMmqK/2783Jg4kI0s4wZBWebRbIHBgoCyA== dependencies: "@vueuse/core" "^9.12.0" ant-design-vue "^3.2.15"