2024-07-01 15:39:32 +08:00
|
|
|
<script setup lang="ts">
|
2025-06-25 14:15:13 +08:00
|
|
|
import {fetchGetSystemVarList} from "@/service/api/system-variable";
|
|
|
|
import { onMounted, ref, computed} from 'vue'
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
getSystemVariables();
|
|
|
|
});
|
|
|
|
|
2024-07-01 15:39:32 +08:00
|
|
|
const content = defineModel<{ key: string; value: string | number | boolean; type: string }[]>('value', {
|
|
|
|
required: true,
|
|
|
|
default: () => []
|
|
|
|
});
|
|
|
|
|
|
|
|
const path = defineModel<string>('path', {
|
|
|
|
required: true
|
|
|
|
});
|
|
|
|
|
|
|
|
const onCreate = () => {
|
|
|
|
return {
|
|
|
|
key: '',
|
|
|
|
value: '',
|
|
|
|
type: 'string'
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const dynamicInputRule = [
|
|
|
|
{
|
|
|
|
trigger: ['input', 'blur'],
|
2024-07-03 09:30:20 +08:00
|
|
|
validator(_: unknown, value: string | number) {
|
|
|
|
if (!value && value !== 0) return new Error('不能为空');
|
2024-07-01 15:39:32 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
2025-06-25 14:15:13 +08:00
|
|
|
const inputValue = ref('');
|
|
|
|
const syncOptions = ref([
|
|
|
|
{
|
|
|
|
label: String,
|
|
|
|
value: String
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
|
|
|
|
const getSystemVariables = async () =>{
|
|
|
|
const { error,data } = await fetchGetSystemVarList();
|
|
|
|
if (!error) {
|
|
|
|
syncOptions.value = data.map(item => ({
|
|
|
|
label: item.variableName,
|
|
|
|
value: item.variableKey.replace("$",'')
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-07-01 15:39:32 +08:00
|
|
|
|
|
|
|
const typeOptions = [
|
|
|
|
{
|
|
|
|
label: 'string',
|
|
|
|
value: 'string'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'number',
|
|
|
|
value: 'number'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'boolean',
|
|
|
|
value: 'boolean'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
const boolenOptions = [
|
|
|
|
{
|
|
|
|
label: 'true',
|
2024-07-03 09:30:20 +08:00
|
|
|
value: 1
|
2024-07-01 15:39:32 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'false',
|
2024-07-03 09:30:20 +08:00
|
|
|
value: 0
|
2024-07-01 15:39:32 +08:00
|
|
|
}
|
|
|
|
];
|
2024-07-02 15:51:17 +08:00
|
|
|
|
|
|
|
const handleUpdateType = (index: number) => {
|
|
|
|
if (content.value[index].type === 'string') {
|
|
|
|
content.value[index].value = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (content.value[index].type === 'boolean') {
|
2024-07-03 09:30:20 +08:00
|
|
|
content.value[index].value = 0;
|
2024-07-02 15:51:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (content.value[index].type === 'number') {
|
|
|
|
content.value[index].value = 0;
|
|
|
|
}
|
|
|
|
};
|
2024-07-01 15:39:32 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<NDynamicInput v-model:value="content" item-style="margin-bottom: 0;" :on-create="onCreate" #="{ index }">
|
2024-07-05 14:51:41 +08:00
|
|
|
<NGrid>
|
2024-07-03 09:30:20 +08:00
|
|
|
<NFormItemGi
|
2024-07-05 14:51:41 +08:00
|
|
|
:span="7"
|
2024-07-01 15:39:32 +08:00
|
|
|
ignore-path-change
|
|
|
|
:show-label="false"
|
|
|
|
:rule="dynamicInputRule"
|
|
|
|
:path="`${path}[${index}].key`"
|
|
|
|
>
|
|
|
|
<NInput v-model:value="content[index].key" placeholder="key" @keydown.enter.prevent />
|
2024-07-03 09:30:20 +08:00
|
|
|
</NFormItemGi>
|
2024-07-05 14:51:41 +08:00
|
|
|
<NGi :span="2" class="h-34px text-center lh-34px">=</NGi>
|
2024-07-03 09:30:20 +08:00
|
|
|
<NFormItemGi
|
2024-07-05 14:51:41 +08:00
|
|
|
:span="7"
|
2024-07-01 15:39:32 +08:00
|
|
|
ignore-path-change
|
|
|
|
:show-label="false"
|
|
|
|
:rule="dynamicInputRule"
|
|
|
|
:path="`${path}[${index}].value`"
|
|
|
|
>
|
2025-06-25 14:15:13 +08:00
|
|
|
<!-- <NInput-->
|
|
|
|
<!-- v-if="content[index].type === 'string'"-->
|
|
|
|
<!-- v-model:value="content[index].value as string"-->
|
|
|
|
<!-- placeholder="value"-->
|
|
|
|
<!-- @keydown.enter.prevent-->
|
|
|
|
<!-- />-->
|
|
|
|
|
|
|
|
<n-mention
|
2024-07-01 15:39:32 +08:00
|
|
|
v-if="content[index].type === 'string'"
|
|
|
|
v-model:value="content[index].value as string"
|
|
|
|
placeholder="value"
|
2025-06-25 14:15:13 +08:00
|
|
|
:options="syncOptions"
|
|
|
|
default-value="@"
|
|
|
|
:prefix="['$']"
|
2024-07-01 15:39:32 +08:00
|
|
|
@keydown.enter.prevent
|
|
|
|
/>
|
2025-06-25 14:15:13 +08:00
|
|
|
<NPopover trigger="hover"
|
|
|
|
v-if="content[index].type === 'string'"
|
|
|
|
>
|
|
|
|
<template #trigger>
|
|
|
|
<NButton text>
|
|
|
|
<SvgIcon icon="ant-design:info-circle-outlined" class="text-18px color-blue" />
|
|
|
|
</NButton>
|
|
|
|
</template>
|
|
|
|
输入$提示变量信息
|
|
|
|
</NPopover>
|
|
|
|
|
2024-07-01 15:39:32 +08:00
|
|
|
<NInputNumber
|
|
|
|
v-if="content[index].type === 'number'"
|
|
|
|
v-model:value="content[index].value as number"
|
2024-07-03 09:30:20 +08:00
|
|
|
class="w-full"
|
2024-07-01 15:39:32 +08:00
|
|
|
placeholder="value"
|
|
|
|
@keydown.enter.prevent
|
|
|
|
/>
|
|
|
|
<NSelect
|
2024-07-02 15:51:17 +08:00
|
|
|
v-if="content[index].type === 'boolean'"
|
2024-07-01 15:39:32 +08:00
|
|
|
v-model:value="content[index].value as number"
|
2024-07-03 09:30:20 +08:00
|
|
|
class="w-full"
|
2024-07-01 15:39:32 +08:00
|
|
|
:options="boolenOptions"
|
|
|
|
placeholder="value"
|
|
|
|
@keydown.enter.prevent
|
|
|
|
/>
|
2024-07-03 09:30:20 +08:00
|
|
|
</NFormItemGi>
|
2024-07-05 14:51:41 +08:00
|
|
|
<NFormItemGi
|
|
|
|
:span="3"
|
|
|
|
class="ml-12px w-115px"
|
|
|
|
ignore-path-change
|
|
|
|
:show-label="false"
|
|
|
|
:path="`${path}[${index}].type`"
|
|
|
|
>
|
|
|
|
<div class="h-34px lh-34px">(</div>
|
2024-07-01 15:39:32 +08:00
|
|
|
<NSelect
|
|
|
|
v-model:value="content[index].type"
|
2024-07-03 09:30:20 +08:00
|
|
|
class="mx-3px"
|
2024-07-01 15:39:32 +08:00
|
|
|
:options="typeOptions"
|
|
|
|
placeholder="字段类型"
|
|
|
|
@keydown.enter.prevent
|
2024-07-02 15:51:17 +08:00
|
|
|
@update:value="handleUpdateType(index)"
|
2024-07-01 15:39:32 +08:00
|
|
|
/>
|
2024-07-05 14:51:41 +08:00
|
|
|
<div class="h-34px lh-34px">)</div>
|
2024-07-03 09:30:20 +08:00
|
|
|
</NFormItemGi>
|
|
|
|
</NGrid>
|
2024-07-01 15:39:32 +08:00
|
|
|
</NDynamicInput>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<style scoped></style>
|