|
|
@@ -1,141 +1,149 @@
|
|
|
<template>
|
|
|
- <el-scrollbar height="calc(100vh - 130px)" class="config">
|
|
|
- <ViewTitle :title="t('pageVariables')">
|
|
|
- <template #right>
|
|
|
- <el-button text @click="addPageVariables"
|
|
|
- ><el-icon class="cursor-pointer"> <Plus /> </el-icon
|
|
|
- ></el-button>
|
|
|
- </template>
|
|
|
- </ViewTitle>
|
|
|
- <div class="p-10px">
|
|
|
- <!-- 变量表格 -->
|
|
|
- <el-table :data="pageVariables || []">
|
|
|
- <el-table-column :label="t('variableName')">
|
|
|
- <template #default="{ row }">
|
|
|
- <el-input
|
|
|
- spellcheck="false"
|
|
|
- v-model="row.name"
|
|
|
- placeholder="请输入"
|
|
|
- @input="(val) => handleVariableNameInput(row, val)"
|
|
|
- />
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column :label="t('variableType')">
|
|
|
- <template #default="{ row }">
|
|
|
- <el-select v-model="row.type" placeholder="请选择">
|
|
|
- <el-option
|
|
|
- v-for="type in variableType"
|
|
|
- :key="type.value"
|
|
|
- :label="type.label"
|
|
|
- :value="type.value"
|
|
|
- />
|
|
|
- </el-select>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column :label="t('initialValue')">
|
|
|
- <template #default="{ row }">
|
|
|
- <el-input spellcheck="false" v-model="row.value" placeholder="请输入" />
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column width="40">
|
|
|
- <template #default="{ row }">
|
|
|
- <el-icon
|
|
|
- class="cursor-pointer"
|
|
|
- @click="handleVariablesRemove(pageVariables || [], row, 'page')"
|
|
|
- >
|
|
|
- <Delete />
|
|
|
- </el-icon>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- </el-table>
|
|
|
- </div>
|
|
|
-
|
|
|
- <ViewTitle :title="t('globalVariables')">
|
|
|
- <template #right>
|
|
|
- <el-button text @click="addVariableGroup"
|
|
|
- ><el-icon class="cursor-pointer"> <Plus /> </el-icon
|
|
|
- ></el-button>
|
|
|
- </template>
|
|
|
- </ViewTitle>
|
|
|
- <el-form label-position="top">
|
|
|
- <el-collapse v-for="item in globalVariables" :key="item.id" v-model="activeNames">
|
|
|
- <el-collapse-item :name="item.id">
|
|
|
- <template #title>
|
|
|
- <div class="collapse-title">
|
|
|
- <el-icon class="arrow" :class="{ active: activeNames.includes(item.id) }">
|
|
|
- <ArrowRight />
|
|
|
- </el-icon>
|
|
|
-
|
|
|
- <span class="title-text mr-12px flex items-center">
|
|
|
+ <div class="w-full h-full" style="height: calc(100vh - 130px)">
|
|
|
+ <SplitterCollapse>
|
|
|
+ <SplitterCollapseItem :title="t('pageVariables')">
|
|
|
+ <template #header-right>
|
|
|
+ <el-button text @click.stop="addPageVariables">
|
|
|
+ <el-icon class="cursor-pointer"> <Plus /> </el-icon>
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ <div class="p-10px">
|
|
|
+ <!-- 变量表格 -->
|
|
|
+ <el-table :data="pageVariables || []">
|
|
|
+ <el-table-column :label="t('variableName')">
|
|
|
+ <template #default="{ row }">
|
|
|
<el-input
|
|
|
- v-model="item.name"
|
|
|
- placeholder="请输入组名"
|
|
|
- size="small"
|
|
|
- class="mt-10px mb-10px"
|
|
|
+ spellcheck="false"
|
|
|
+ v-model="row.name"
|
|
|
+ placeholder="请输入"
|
|
|
+ @input="(val) => handleVariableNameInput(row, val)"
|
|
|
/>
|
|
|
- </span>
|
|
|
-
|
|
|
- <el-icon class="mr-10px" @click.stop="addVariables(item.variables)">
|
|
|
- <Plus />
|
|
|
- </el-icon>
|
|
|
- <el-icon @click.stop="removeVariables(item)">
|
|
|
- <Delete />
|
|
|
- </el-icon>
|
|
|
- </div>
|
|
|
- </template>
|
|
|
- <div class="p-10px">
|
|
|
- <!-- 变量表格 -->
|
|
|
- <el-table :data="item.variables">
|
|
|
- <el-table-column :label="t('variableName')">
|
|
|
- <template #default="{ row }">
|
|
|
- <el-input
|
|
|
- spellcheck="false"
|
|
|
- v-model="row.name"
|
|
|
- placeholder="请输入"
|
|
|
- @input="(val) => handleVariableNameInput(row, val)"
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('variableType')">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-select
|
|
|
+ v-model="row.type"
|
|
|
+ placeholder="请选择"
|
|
|
+ :disabled="isVariableUsed(row.id)"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="type in variableType"
|
|
|
+ :key="type.value"
|
|
|
+ :label="type.label"
|
|
|
+ :value="type.value"
|
|
|
/>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column :label="t('variableType')">
|
|
|
- <template #default="{ row }">
|
|
|
- <el-select v-model="row.type" placeholder="请选择">
|
|
|
- <el-option
|
|
|
- v-for="type in variableType"
|
|
|
- :key="type.value"
|
|
|
- :label="type.label"
|
|
|
- :value="type.value"
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('initialValue')">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-input spellcheck="false" v-model="row.value" placeholder="请输入" />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column width="40">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-icon
|
|
|
+ class="cursor-pointer"
|
|
|
+ @click="handleVariablesRemove(pageVariables || [], row, 'page')"
|
|
|
+ >
|
|
|
+ <Delete />
|
|
|
+ </el-icon>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </div>
|
|
|
+ </SplitterCollapseItem>
|
|
|
+
|
|
|
+ <SplitterCollapseItem :title="t('globalVariables')">
|
|
|
+ <template #header-right>
|
|
|
+ <el-button text @click.stop="addVariableGroup">
|
|
|
+ <el-icon class="cursor-pointer"> <Plus /> </el-icon>
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ <el-form label-position="top">
|
|
|
+ <el-collapse v-for="item in globalVariables" :key="item.id" v-model="activeNames">
|
|
|
+ <el-collapse-item :name="item.id">
|
|
|
+ <template #title>
|
|
|
+ <div class="collapse-title">
|
|
|
+ <el-icon class="arrow" :class="{ active: activeNames.includes(item.id) }">
|
|
|
+ <ArrowRight />
|
|
|
+ </el-icon>
|
|
|
+
|
|
|
+ <span class="title-text mr-12px flex items-center">
|
|
|
+ <el-input
|
|
|
+ v-model="item.name"
|
|
|
+ placeholder="请输入组名"
|
|
|
+ size="small"
|
|
|
+ class="mt-10px mb-10px"
|
|
|
/>
|
|
|
- </el-select>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column :label="t('initialValue')">
|
|
|
- <template #default="{ row }">
|
|
|
- <el-input spellcheck="false" v-model="row.value" placeholder="请输入" />
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- <el-table-column width="40">
|
|
|
- <template #default="{ row }">
|
|
|
- <el-icon
|
|
|
- class="cursor-pointer"
|
|
|
- @click="handleVariablesRemove(item.variables, row, 'global')"
|
|
|
- >
|
|
|
+ </span>
|
|
|
+
|
|
|
+ <el-icon class="mr-10px" @click.stop="addVariables(item.variables)">
|
|
|
+ <Plus />
|
|
|
+ </el-icon>
|
|
|
+ <el-icon @click.stop="removeVariables(item)">
|
|
|
<Delete />
|
|
|
</el-icon>
|
|
|
- </template>
|
|
|
- </el-table-column>
|
|
|
- </el-table>
|
|
|
- </div>
|
|
|
- </el-collapse-item>
|
|
|
- </el-collapse>
|
|
|
- <el-empty v-if="globalVariables.length === 0" description="暂无全局变量" />
|
|
|
- </el-form>
|
|
|
- </el-scrollbar>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ <div class="p-10px">
|
|
|
+ <!-- 变量表格 -->
|
|
|
+ <el-table :data="item.variables">
|
|
|
+ <el-table-column :label="t('variableName')">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-input
|
|
|
+ spellcheck="false"
|
|
|
+ v-model="row.name"
|
|
|
+ placeholder="请输入"
|
|
|
+ @input="(val) => handleVariableNameInput(row, val)"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('variableType')">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-select
|
|
|
+ v-model="row.type"
|
|
|
+ placeholder="请选择"
|
|
|
+ :disabled="isVariableUsed(row.id)"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="type in variableType"
|
|
|
+ :key="type.value"
|
|
|
+ :label="type.label"
|
|
|
+ :value="type.value"
|
|
|
+ />
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column :label="t('initialValue')">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-input spellcheck="false" v-model="row.value" placeholder="请输入" />
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column width="40">
|
|
|
+ <template #default="{ row }">
|
|
|
+ <el-icon
|
|
|
+ class="cursor-pointer"
|
|
|
+ @click="handleVariablesRemove(item.variables, row, 'global')"
|
|
|
+ >
|
|
|
+ <Delete />
|
|
|
+ </el-icon>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </div>
|
|
|
+ </el-collapse-item>
|
|
|
+ </el-collapse>
|
|
|
+ <el-empty v-if="globalVariables.length === 0" description="暂无全局变量" />
|
|
|
+ </el-form>
|
|
|
+ </SplitterCollapseItem>
|
|
|
+ </SplitterCollapse>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import { computed, ref } from 'vue'
|
|
|
-import type { Variable, VariableGroup } from '@/types/variables'
|
|
|
-import type { BaseWidget } from '@/types/baseWidget'
|
|
|
import { ArrowRight, Plus, Delete } from '@element-plus/icons-vue'
|
|
|
import { ElMessageBox } from 'element-plus'
|
|
|
import { variableType } from '@/constants'
|
|
|
@@ -143,6 +151,10 @@ import { v4 } from 'uuid'
|
|
|
import { useI18n } from 'vue-i18n'
|
|
|
import { useProjectStore } from '@/store/modules/project'
|
|
|
import { findVariableUsages } from '@/utils/variableBinding'
|
|
|
+import { SplitterCollapse, SplitterCollapseItem } from '@/components/SplitterCollapse'
|
|
|
+
|
|
|
+import type { Variable, VariableGroup } from '@/types/variables'
|
|
|
+import type { BaseWidget } from '@/types/baseWidget'
|
|
|
|
|
|
interface Emits {
|
|
|
(e: 'update:variables', val: VariableGroup[]): void
|
|
|
@@ -178,7 +190,7 @@ const handleVariableNameInput = (row: Variable, value: string) => {
|
|
|
}
|
|
|
|
|
|
const addVariables = (variables) => {
|
|
|
- variables.push({
|
|
|
+ variables.unshift({
|
|
|
id: v4(),
|
|
|
name: `var_${variables.length + 1}`,
|
|
|
value: '',
|
|
|
@@ -199,7 +211,7 @@ const walkWidgets = (widgets: BaseWidget[] = [], callback: (widget: BaseWidget)
|
|
|
const addPageVariables = () => {
|
|
|
// todo: 打开弹窗,列出当前页面全部控件,然后根据控件属性选择变量
|
|
|
// 选择属性后会自动绑定属性的变量类型,初始值使用属性的当前值
|
|
|
- props.pageVariables?.push({
|
|
|
+ props.pageVariables?.unshift({
|
|
|
id: v4(),
|
|
|
name: '',
|
|
|
value: '',
|
|
|
@@ -207,6 +219,18 @@ const addPageVariables = () => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 变量是否被使用
|
|
|
+ */
|
|
|
+const isVariableUsed = (varId: string) => {
|
|
|
+ const pages = projectStore.project?.screens.flatMap((item) => item.pages) || []
|
|
|
+ const usageCount = findVariableUsages(varId, [
|
|
|
+ { children: pages }
|
|
|
+ ] as unknown as BaseWidget[]).length
|
|
|
+
|
|
|
+ return usageCount > 0
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* 删除变量操作
|
|
|
* @variables 变量列表
|
|
|
@@ -226,8 +250,10 @@ const handleVariablesRemove = (
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const pageChildren = projectStore.activePage?.children || []
|
|
|
- const usageCount = findVariableUsages(varItem.id, pageChildren).length
|
|
|
+ const pages = projectStore.project?.screens.flatMap((item) => item.pages) || []
|
|
|
+ const usageCount = findVariableUsages(varItem.id, [
|
|
|
+ { children: pages }
|
|
|
+ ] as unknown as BaseWidget[]).length
|
|
|
|
|
|
if (usageCount === 0) {
|
|
|
deleteVariable()
|
|
|
@@ -270,7 +296,7 @@ const removeVariables = (variables) => {
|
|
|
*/
|
|
|
const addVariableGroup = () => {
|
|
|
const id = v4()
|
|
|
- globalVariables.value.push({
|
|
|
+ globalVariables.value.unshift({
|
|
|
id,
|
|
|
name: `vargroup_${globalVariables.value.length + 1}`,
|
|
|
variables: []
|