update: 设备功能调试, 精简模式新增字段必填验证

This commit is contained in:
JiangQiming 2023-02-23 14:30:03 +08:00
parent 7000ccd85b
commit b239bfc8b2
1 changed files with 101 additions and 72 deletions

View File

@ -14,60 +14,79 @@
> >
<a-row :gutter="30"> <a-row :gutter="30">
<a-col :span="15"> <a-col :span="15">
<a-table <a-form :ref="`${func.id}Ref`" :model="func">
:columns="columns" <a-table
:data-source="func.table" :columns="columns"
:pagination="false" :data-source="func.table"
rowKey="id" :pagination="false"
> rowKey="id"
<template #bodyCell="{ column, text, record }"> >
<template v-if="column.dataIndex === 'type'"> <template #bodyCell="{ column, record, index }">
<span>{{ record.type }}</span> <template
<a-tooltip v-if="record.type === 'object'"> v-if="column.dataIndex === 'type'"
<template slot="title"> >
请按照json格式输入 <span>{{ record.type }}</span>
</template> <a-tooltip
v-if="record.type === 'object'"
>
<template slot="title">
请按照json格式输入
</template>
<AIcon <AIcon
type="QuestionCircleOutlined" type="QuestionCircleOutlined"
:style="{ :style="{
marginLeft: '5px', marginLeft: '5px',
cursor: 'help', cursor: 'help',
}"
/>
</a-tooltip>
</template>
<template
v-if="column.dataIndex === 'value'"
>
<a-form-item
:name="['table', index, 'value']"
:rules="{
required: true,
message: '',
}" }"
/> has-feedback
</a-tooltip> >
<ValueItem
:ref="`valueItemRef${record.id}`"
v-model:modelValue="
record.value
"
:itemType="record.type"
:options="
record.type === 'enum'
? (
record?.options
?.elements || []
).map((item:any) => ({
label: item.text,
value: item.value,
}))
: record.type === 'boolean'
? [
{
label: '是',
value: true,
},
{
label: '否',
value: false,
},
]
: undefined
"
/>
</a-form-item>
</template>
</template> </template>
<template v-if="column.dataIndex === 'value'"> </a-table>
<ValueItem </a-form>
:ref="`valueItemRef${record.id}`"
v-model:modelValue="record.value"
:itemType="record.type"
:options="
record.type === 'enum'
? (
record?.options
?.elements || []
).map((item:any) => ({
label: item.text,
value: item.value,
}))
: record.type === 'boolean'
? [
{
label: '是',
value: true,
},
{
label: '否',
value: false,
},
]
: undefined
"
/>
</template>
</template>
</a-table>
<div class="editor-btn"> <div class="editor-btn">
<a-space> <a-space>
<a-button <a-button
@ -180,36 +199,46 @@ const newFunctions = computed(() => {
* 执行 * 执行
*/ */
const handleExecute = async (func: any) => { const handleExecute = async (func: any) => {
const obj = {}; proxy?.$refs[`${func.id}Ref`][0]
func.table.forEach((item: any) => { .validate()
if (item.type === 'object') { .then(async () => {
obj[item.id] = JSON.parse(item.value); const obj = {};
} else { func.table.forEach((item: any) => {
obj[item.id] = item.value; if (item.type === 'object') {
} obj[item.id] = JSON.parse(item.value);
}); } else {
const { success, result } = await execute( obj[item.id] = item.value;
route.params.id as string, }
func.id, });
obj, const { success, result } = await execute(
); route.params.id as string,
if (!success) return; func.id,
message.success('操作成功'); obj,
func.executeResult = result instanceof Array ? result[0] : result; );
proxy?.$forceUpdate(); if (!success) return;
message.success('操作成功');
func.executeResult = result instanceof Array ? result[0] : result;
proxy?.$forceUpdate();
})
.catch((err: any) => {
console.log('err: ', err);
});
}; };
/** /**
* 清空 * 清空
*/ */
const handleClear = (func: any) => { const handleClear = (func: any) => {
func.table.forEach((item: any) => { proxy?.$refs[`${func.id}Ref`][0].resetFields();
item.value = undefined;
proxy.$refs[`valueItemRef${item.id}`][0].myValue = undefined;
});
}; };
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
:deep(.ant-table-cell .ant-form-item) {
margin-bottom: 0;
}
:deep(.ant-form-item-with-help .ant-form-item-explain) {
min-height: 0;
}
.wrapper { .wrapper {
.tips { .tips {
margin-bottom: 10px; margin-bottom: 10px;