|
@@ -18,8 +18,8 @@
|
|
|
<t-input v-model="item.value" />
|
|
|
</div>
|
|
|
<div class="actions">
|
|
|
- <t-tooltip content="数据绑定" placement="top">
|
|
|
- <t-icon name="link" class="hover" style="visibility: visible" />
|
|
|
+ <t-tooltip content="变量绑定" placement="top">
|
|
|
+ <t-icon name="link" class="hover" @click="onBind(item)" />
|
|
|
</t-tooltip>
|
|
|
<t-dropdown
|
|
|
:options="moreOptions"
|
|
@@ -128,18 +128,75 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
</t-dialog>
|
|
|
+
|
|
|
+ <t-dialog
|
|
|
+ v-if="dataBindDialog.show"
|
|
|
+ :visible="true"
|
|
|
+ class="data-link-dialog"
|
|
|
+ header="变量绑定"
|
|
|
+ @close="dataBindDialog.show = false"
|
|
|
+ @confirm="dataBindDialog.show = false"
|
|
|
+ :width="700"
|
|
|
+ >
|
|
|
+ <div class="form-item">
|
|
|
+ <label>当前绑定:</label>
|
|
|
+ <div class="label" v-if="dataBindDialog.data.binds?.length">
|
|
|
+ <t-tooltip
|
|
|
+ v-for="(tag, index) in dataBindDialog.data.binds"
|
|
|
+ :key="index"
|
|
|
+ :content="tag.id"
|
|
|
+ >
|
|
|
+ <t-tag class="mr-8 mb-8" closable @close="onRemoveBind(index)">
|
|
|
+ {{ tag.label }}
|
|
|
+ </t-tag>
|
|
|
+ </t-tooltip>
|
|
|
+ </div>
|
|
|
+ <div class="label gray" v-else>无</div>
|
|
|
+ </div>
|
|
|
+ <div class="form-item mt-8">
|
|
|
+ <t-input
|
|
|
+ placeholder="搜索"
|
|
|
+ v-model="dataBindDialog.input"
|
|
|
+ @change="onSearchDataSet"
|
|
|
+ @enter="onSearchDataSet"
|
|
|
+ >
|
|
|
+ <template #suffixIcon>
|
|
|
+ <t-icon name="search" class="hover" @click="onSearchDataSet" />
|
|
|
+ </template>
|
|
|
+ </t-input>
|
|
|
+ </div>
|
|
|
+ <t-table
|
|
|
+ class="mt-12 data-list"
|
|
|
+ row-key="id"
|
|
|
+ :data="dataBindDialog.dataSet"
|
|
|
+ :columns="dataSetColumns"
|
|
|
+ size="small"
|
|
|
+ bordered
|
|
|
+ :loading="dataBindDialog.loading"
|
|
|
+ :pagination="query"
|
|
|
+ @page-change="onChangePagination"
|
|
|
+ :selected-row-keys="dataBindDialog.selectedIds"
|
|
|
+ @select-change="onSelectBindsChange"
|
|
|
+ >
|
|
|
+ </t-table>
|
|
|
+ </t-dialog>
|
|
|
</template>
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
-import { onBeforeMount, reactive, ref } from 'vue';
|
|
|
-
|
|
|
+import { onBeforeMount, reactive, ref, toRaw } from 'vue';
|
|
|
+import { useRoute, useRouter } from 'vue-router';
|
|
|
import { MessagePlugin } from 'tdesign-vue-next';
|
|
|
+import axios from 'axios';
|
|
|
+import { debounce } from '@/services/debouce';
|
|
|
+
|
|
|
+const route = useRoute();
|
|
|
+const router = useRouter();
|
|
|
|
|
|
const { pen } = defineProps<{
|
|
|
pen: any;
|
|
|
}>();
|
|
|
|
|
|
-const options: any[] = ref([
|
|
|
+const options = ref<any>([
|
|
|
{
|
|
|
value: '',
|
|
|
content: '自定义',
|
|
@@ -198,7 +255,7 @@ const options: any[] = ref([
|
|
|
},
|
|
|
]);
|
|
|
|
|
|
-const moreOptions: any[] = ref([
|
|
|
+const moreOptions = ref<any>([
|
|
|
{
|
|
|
value: 'edit',
|
|
|
content: '编辑',
|
|
@@ -223,11 +280,53 @@ const typeOptions = [
|
|
|
},
|
|
|
];
|
|
|
|
|
|
-const addDataDialog = reactive({
|
|
|
+const addDataDialog = reactive<any>({
|
|
|
show: false,
|
|
|
data: undefined,
|
|
|
});
|
|
|
|
|
|
+const dataBindDialog = reactive<any>({
|
|
|
+ show: false,
|
|
|
+ data: undefined,
|
|
|
+});
|
|
|
+
|
|
|
+const dataSetColumns = [
|
|
|
+ {
|
|
|
+ colKey: 'row-select',
|
|
|
+ type: 'multiple',
|
|
|
+ width: 50,
|
|
|
+ },
|
|
|
+ {
|
|
|
+ colKey: 'id',
|
|
|
+ title: '编号',
|
|
|
+ width: 150,
|
|
|
+ ellipsis: { theme: 'light', trigger: 'context-menu' },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ colKey: 'label',
|
|
|
+ title: '变量名称',
|
|
|
+ width: 220,
|
|
|
+ ellipsis: { theme: 'light', trigger: 'context-menu' },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ colKey: 'case',
|
|
|
+ title: '场景',
|
|
|
+ ellipsis: { theme: 'light', trigger: 'context-menu' },
|
|
|
+ },
|
|
|
+];
|
|
|
+
|
|
|
+const query = reactive<{
|
|
|
+ current: number;
|
|
|
+ pageSize: number;
|
|
|
+ total: number;
|
|
|
+ range: any[];
|
|
|
+}>({
|
|
|
+ current: 1,
|
|
|
+ pageSize: 10,
|
|
|
+ total: 0,
|
|
|
+ range: [],
|
|
|
+});
|
|
|
+
|
|
|
onBeforeMount(() => {
|
|
|
if (pen.realTimesOptions) {
|
|
|
options.value[options.value.length - 1].divider = true;
|
|
@@ -236,6 +335,20 @@ onBeforeMount(() => {
|
|
|
});
|
|
|
|
|
|
const addRealTime = (e: any) => {
|
|
|
+ if (e.keywords) {
|
|
|
+ if (!pen.realTimes) {
|
|
|
+ pen.realTimes = [];
|
|
|
+ }
|
|
|
+
|
|
|
+ pen.realTimes.push({
|
|
|
+ label: e.content,
|
|
|
+ key: e.value,
|
|
|
+ type: e.type,
|
|
|
+ keywords: e.keywords,
|
|
|
+ });
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
addDataDialog.header = '添加动态数据';
|
|
|
|
|
|
addDataDialog.data = {
|
|
@@ -244,7 +357,7 @@ const addRealTime = (e: any) => {
|
|
|
type: e.type,
|
|
|
keywords: e.keywords,
|
|
|
};
|
|
|
- if (!e.keywords) {
|
|
|
+ if (e.keywords) {
|
|
|
addDataDialog.data.label = '';
|
|
|
}
|
|
|
addDataDialog.show = true;
|
|
@@ -266,7 +379,7 @@ const onConfirmData = () => {
|
|
|
}
|
|
|
|
|
|
if (addDataDialog.header === '添加动态数据') {
|
|
|
- const found = pen.realTimes.findIndex((item) => {
|
|
|
+ const found = pen.realTimes.findIndex((item: any) => {
|
|
|
return item.key === addDataDialog.data.key;
|
|
|
});
|
|
|
if (found > -1) {
|
|
@@ -293,6 +406,86 @@ const onMenuMore = (e: any, item: any, i: number) => {
|
|
|
break;
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+const onBind = (item: any) => {
|
|
|
+ if (!item.binds) {
|
|
|
+ item.binds = [];
|
|
|
+ }
|
|
|
+ dataBindDialog.data = item;
|
|
|
+ dataBindDialog.input = '';
|
|
|
+ dataBindDialog.selectedIds = [];
|
|
|
+ for (const i of item.binds) {
|
|
|
+ dataBindDialog.selectedIds.push(i.id);
|
|
|
+ }
|
|
|
+
|
|
|
+ dataBindDialog.show = true;
|
|
|
+
|
|
|
+ getDataSet();
|
|
|
+};
|
|
|
+
|
|
|
+const onSearchDataSet = () => {
|
|
|
+ debounce(getDataSet, 300);
|
|
|
+};
|
|
|
+
|
|
|
+const getDataSet = async () => {
|
|
|
+ // @ts-ignore
|
|
|
+ const data: Meta2dBackData = meta2d.data();
|
|
|
+
|
|
|
+ dataBindDialog.loading = true;
|
|
|
+
|
|
|
+ // 应该从data获取url或结果列表
|
|
|
+ const ret: any = await axios.get(
|
|
|
+ `/api/device/data/set?mock=1&q=${dataBindDialog.input}¤t=${query.current}&pageSize=${query.pageSize}`
|
|
|
+ );
|
|
|
+
|
|
|
+ dataBindDialog.dataSet = ret.list;
|
|
|
+ query.total = ret.total;
|
|
|
+ dataBindDialog.loading = false;
|
|
|
+};
|
|
|
+
|
|
|
+const onChangePagination = (pageInfo: any) => {
|
|
|
+ router.push({
|
|
|
+ path: route.path,
|
|
|
+ query: { current: pageInfo.current, pageSize: pageInfo.pageSize },
|
|
|
+ });
|
|
|
+ query.current = pageInfo.current;
|
|
|
+ query.pageSize = pageInfo.pageSize;
|
|
|
+ getDataSet();
|
|
|
+};
|
|
|
+
|
|
|
+const onSelectBindsChange = (value: string[], options: any) => {
|
|
|
+ dataBindDialog.selectedIds = value;
|
|
|
+ console.log(options);
|
|
|
+
|
|
|
+ if (options.type === 'check') {
|
|
|
+ for (const item of options.selectedRowData) {
|
|
|
+ const found = dataBindDialog.data.binds.findIndex((elem: any) => {
|
|
|
+ return elem.id === item.id;
|
|
|
+ });
|
|
|
+ if (found < 0) {
|
|
|
+ dataBindDialog.data.binds.push(toRaw(item));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (options.type === 'uncheck') {
|
|
|
+ if (options.currentRowKey === 'CHECK_ALL_BOX') {
|
|
|
+ for (const data of dataBindDialog.dataSet) {
|
|
|
+ const found = dataBindDialog.data.binds.findIndex((elem: any) => {
|
|
|
+ return elem.id === data.id;
|
|
|
+ });
|
|
|
+ if (found > -1) {
|
|
|
+ dataBindDialog.data.binds.splice(found, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ const found = dataBindDialog.data.binds.findIndex((elem: any) => {
|
|
|
+ return elem.id === options.currentRowKey;
|
|
|
+ });
|
|
|
+ if (found > -1) {
|
|
|
+ dataBindDialog.data.binds.splice(found, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
</script>
|
|
|
<style lang="postcss" scoped>
|
|
|
.props {
|
|
@@ -334,5 +527,10 @@ const onMenuMore = (e: any, item: any, i: number) => {
|
|
|
margin-left: 6px;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ .data-list {
|
|
|
+ height: 300px;
|
|
|
+ overflow: auto;
|
|
|
+ }
|
|
|
}
|
|
|
</style>
|