fix: bug#10782

This commit is contained in:
xieyonghong 2023-03-23 18:41:52 +08:00
parent cb035bce38
commit 96c6b69aef
10 changed files with 83 additions and 50 deletions

View File

@ -108,4 +108,29 @@ export const onlyMessage = (msg: string, type: 'success' | 'error' | 'warning' =
content: msg, content: msg,
key: type 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})
} }

View File

@ -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 * @param {Object} error
@ -128,44 +138,19 @@ const errorHandler = (error: any) => {
const data = error.response.data const data = error.response.data
const status = error.response.status const status = error.response.status
if (status === 403) { if (status === 403) {
Notification.error({ showNotification( 'Forbidden', (data.message + '').substr(0, 90), '403')
key: '403',
message: 'Forbidden',
description: (data.message + '').substr(0, 90)
})
setTimeout(() => {
router.push({
name: 'Exception403'
})
}, 0)
} else if (status === 500) { } else if (status === 500) {
Notification.error({ showNotification( 'Server Side Error', (data.message + '').substr(0, 90), '500')
key: '500',
message: 'Server Side Error',
description: (data.message + '').substr(0, 90)
})
} else if (status === 400) { } else if (status === 400) {
Notification.error({ showNotification( 'Request Error', (data.message + '').substr(0, 90), '400')
key: '400',
message: 'Request Error',
description: (data.message + '').substr(0, 90)
})
} else if (status === 401) { } else if (status === 401) {
Notification.error({ showNotification( 'Unauthorized', '用户未登录', '401')
key: '401',
message: 'Unauthorized',
description: '用户未登录'
})
setTimeout(() => { setTimeout(() => {
location.href = `/#${LoginPath}` location.href = `/#${LoginPath}`
}, 0) }, 0)
} }
} else if (error.response === undefined) { } else if (error.response === undefined) {
Notification.error({ showNotification( error.message, (error.stack + '').substr(0, 90), undefined)
message: error.message,
description: (error.stack + '').substr(0, 90)
})
} }
return Promise.reject(error) return Promise.reject(error)
} }

View File

@ -111,7 +111,7 @@ import {
getProtocolDetail, getProtocolDetail,
} from '@/api/device/product'; } from '@/api/device/product';
import { message } from 'jetlinks-ui-components'; import { message } from 'jetlinks-ui-components';
import { getImage } from '@/utils/comm'; import { getImage, handleParamsToString } from '@/utils/comm'
import encodeQuery from '@/utils/encodeQuery'; import encodeQuery from '@/utils/encodeQuery';
import { useMenuStore } from '@/store/menu'; import { useMenuStore } from '@/store/menu';
@ -286,7 +286,7 @@ const jumpDevice = () => {
{}, {},
{ {
target: 'device-instance', target: 'device-instance',
q: JSON.stringify({ terms: [{ terms: [{ searchParams }] }] }), q: handleParamsToString([searchParams]),
}, },
); );
}; };

View File

@ -188,11 +188,18 @@ const handOptionByColumn = (option: any) => {
} }
} }
watchEffect(() => { watch(() => [columnOptions.value, paramsValue.column], () => {
if (!props.value.error && props.value.column) { // option if (paramsValue.column) {
const option = getOption(columnOptions.value, paramsValue.column, 'id') const option = getOption(columnOptions.value, paramsValue.column, 'id')
if (option) { if (option && Object.keys(option).length) {
handOptionByColumn(option) handOptionByColumn(option)
if (props.value.error) {
emit('update:value', {
...props.value,
error: false
})
formItemContext.onFieldChange()
}
} else { } else {
emit('update:value', { emit('update:value', {
...props.value, ...props.value,
@ -203,6 +210,12 @@ watchEffect(() => {
} }
}) })
watchEffect(() => {
if (!props.value.error && props.value.column) { // option
}
})
const showDouble = computed(() => { const showDouble = computed(() => {
const isRange = paramsValue.termType ? arrayParamsKey.includes(paramsValue.termType) : false const isRange = paramsValue.termType ? arrayParamsKey.includes(paramsValue.termType) : false
return isRange return isRange

View File

@ -213,7 +213,7 @@ const rules = [
return Promise.reject(new Error('请选择操作符')) return Promise.reject(new Error('请选择操作符'))
} }
if (v.value === undefined) { if (v.value.value === undefined) {
return Promise.reject(new Error('请选择或输入参数值')) return Promise.reject(new Error('请选择或输入参数值'))
} else { } else {
if ( if (

View File

@ -81,6 +81,7 @@ import { ContextKey } from './util'
import { useSceneStore } from 'store/scene' import { useSceneStore } from 'store/scene'
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
import { Form } from 'jetlinks-ui-components' import { Form } from 'jetlinks-ui-components'
import { pick } from 'lodash-es'
const sceneStore = useSceneStore() const sceneStore = useSceneStore()
const { data: formModel } = storeToRefs(sceneStore) const { data: formModel } = storeToRefs(sceneStore)
@ -187,11 +188,18 @@ const handOptionByColumn = (option: any) => {
} }
} }
watchEffect(() => { watch(() => [columnOptions.value, paramsValue.column], () => {
if (!props.value.error && props.value.column) { // option if (paramsValue.column) {
const option = getOption(columnOptions.value, paramsValue.column, 'column') const option = getOption(columnOptions.value, paramsValue.column, 'column')
if (option) { if (option && Object.keys(option).length) {
handOptionByColumn(option) handOptionByColumn(option)
if (props.value.error) {
emit('update:value', {
...props.value,
error: false
})
formItemContext.onFieldChange()
}
} else { } else {
emit('update:value', { emit('update:value', {
...props.value, ...props.value,
@ -200,7 +208,7 @@ watchEffect(() => {
formItemContext.onFieldChange() formItemContext.onFieldChange()
} }
} }
}) }, { immediate: true, deep: true })
const showDouble = computed(() => { const showDouble = computed(() => {
const isRange = paramsValue.termType ? arrayParamsKey.includes(paramsValue.termType) : false const isRange = paramsValue.termType ? arrayParamsKey.includes(paramsValue.termType) : false
@ -225,15 +233,17 @@ const mouseout = () => {
} }
const columnSelect = (option: any) => { const columnSelect = (option: any) => {
paramsValue.termType = 'eq' const termTypes = option.termTypes
paramsValue.termType = termTypes?.length ? termTypes[0].id : 'eq'
paramsValue.value = { paramsValue.value = {
source: tabsOptions.value[0].key, source: tabsOptions.value[0].key,
value: undefined value: undefined
} }
emit('update:value', { ...paramsValue }) handOptionByColumn(option)
formItemContext.onFieldChange()
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][0] = option.name
formModel.value.options!.when[props.whenName].terms[props.termsName].terms[props.name][1] = paramsValue.termType 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 }) => { const termsTypeSelect = (e: { key: string, name: string }) => {
@ -242,9 +252,9 @@ const termsTypeSelect = (e: { key: string, name: string }) => {
source: tabsOptions.value[0].key, source: tabsOptions.value[0].key,
value: value value: value
} }
formModel.value.options!.when[props.whenName].terms[props.termsName].terms[props.name][1] = e.name
emit('update:value', { ...paramsValue }) emit('update:value', { ...paramsValue })
formItemContext.onFieldChange() formItemContext.onFieldChange()
formModel.value.options!.when[props.whenName].terms[props.termsName].terms[props.name][1] = e.name
} }
const valueSelect = (_: any, label: string, labelObj: Record<number, any>) => { const valueSelect = (_: any, label: string, labelObj: Record<number, any>) => {
@ -277,7 +287,7 @@ const onDelete = () => {
} }
nextTick(() => { nextTick(() => {
Object.assign(paramsValue, props.value) Object.assign(paramsValue, pick(props.value, ['column', 'options', 'termType', 'terms', 'type', 'value']))
}) })
</script> </script>

View File

@ -120,7 +120,7 @@ const rules = [
return Promise.reject(new Error('请选择操作符')); return Promise.reject(new Error('请选择操作符'));
} }
if (v.value === undefined) { if (!v.value?.value) {
return Promise.reject(new Error('请选择或输入参数值')); return Promise.reject(new Error('请选择或输入参数值'));
} else { } else {
if ( if (

View File

@ -311,7 +311,7 @@ const getActions = (
}, },
icon: 'LikeOutlined', icon: 'LikeOutlined',
popConfirm: { popConfirm: {
title: '', title: '确认手动触发?',
onConfirm: async () => { onConfirm: async () => {
const resp = await _execute(data.id); const resp = await _execute(data.id);
if (resp.status === 200) { if (resp.status === 200) {

View File

@ -92,7 +92,7 @@ export default defineConfig(({ mode}) => {
[env.VITE_APP_BASE_API]: { [env.VITE_APP_BASE_API]: {
// target: 'http://192.168.33.22:8800', // target: 'http://192.168.33.22:8800',
// target: 'http://192.168.32.244:8881', // 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', // 本地开发环境 target: 'http://192.168.33.46:8844', // 本地开发环境
ws: 'ws://192.168.33.46:8844', ws: 'ws://192.168.33.46:8844',
changeOrigin: true, changeOrigin: true,

View File

@ -3700,8 +3700,8 @@ jetlinks-store@^0.0.3:
jetlinks-ui-components@^1.0.5: jetlinks-ui-components@^1.0.5:
version "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" resolved "http://47.108.170.157:9013/jetlinks-ui-components/-/jetlinks-ui-components-1.0.5.tgz#147926716787ac22464b5ce81180ce43a93e40cc"
integrity sha512-vfQ8g8nEJueDkHCVcg9WeWDDjnPklyigbobB1CQArfHLd5O4x6vLFWvF69k0yqytCvIOXB13CzhLtMnv68pC5w== integrity sha512-guypzc4QurKHfVoDrCo28Bx721kbTx8/W9r8jROWINI0J11ZTRi5bMmqK/2783Jg4kI0s4wZBWebRbIHBgoCyA==
dependencies: dependencies:
"@vueuse/core" "^9.12.0" "@vueuse/core" "^9.12.0"
ant-design-vue "^3.2.15" ant-design-vue "^3.2.15"