zhuoyuan.wang
2024-06-19 15ebe96f28cadec6a726c5324593a40bbf56205f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<template>
  <app-list-wrapper v-bind="listWrapperProps">
    <template #header-button="scope">
      <el-button
        size="small"
        icon="Plus"
        type="primary"
        :disabled="!scope.selected?.add?.type_code"
        @click="onOpenForm(scope.selected.add)">
        {{
          $t('common.button.text.add')
        }}
      </el-button>
      <el-button
        size="small"
        type="primary"
        icon="Edit"
        :disabled="!scope.selected?.edit?.id"
        @click="onOpenForm({...scope.selected.edit,...scope.selected.add})"
      >
        {{ $t('common.button.text.edit') }}
      </el-button>
      <el-button
        :disabled="!scope.selected?.edit?.id"
        size="small"
        type="danger"
        icon="Delete"
        @click="onDelete(scope.selected?.edit)"
      >
      </el-button>
    </template>
    <app-layout-row>
      <app-layout-col :span="24">
        <app-table-search
          v-bind="searchProps"
        />
      </app-layout-col>
      <app-layout-col :span="24" :top="10">
        <app-table-pro
          v-bind="tableProps"
        />
      </app-layout-col>
    </app-layout-row>
    <FormDialog v-bind="formDialogProps"/>
  </app-list-wrapper>
</template>
 
<script setup>
 
import {useI18n} from 'vue-i18n';
import {modal} from '@/plugins';
 
const {t} = useI18n();
 
import {meta} from "@/hooks";
 
const {useMetaData} = meta;
 
import {useEntityStore} from '@/store/modules';
import FormDialog from './FormDialog';
 
import {convertFilter} from '@/utils/filter.js';
 
const formDialogRef = ref();
 
const baseColumns = ['code', 'level_code', 'control', 'title', 'business_object_code', 'error_msg_cn', 'error_msg_en', 'error_msg_en', 'notice_msg_cn', 'error_msg_en', 'notice_type'];
 
const codeColumns = {
  'calculate': [...baseColumns],
  'data_standrad': ['object_code', ...baseColumns],
  'format': ['format_content', 'format_type', ...baseColumns],
  'others': [...baseColumns],
  'required': [...baseColumns],
  'unique': [...baseColumns],
}
 
const formDialogProps = {
  ref: formDialogRef,
  subReload(bool) {
    tableProRef.value.getTableData(bool);
  }
}
 
const tableSearchRef = ref();
const tableProRef = ref();
const listWrapperRef = ref();
const entityStore = useEntityStore();
 
const [columns, filters, fields] = useMetaData(
  'sys_library_rule',
  async () => {
    onInit()
  });
 
const tableProps = {
  ref: tableProRef,
  requestParams: {
    base: {},
    search: {}
  },
  complementHeight: 18,
  subRequest: async (page) => {
    const result = await entityStore.getEntitySet({
      dataName: "sys_library_rule",
      filter: convertFilter({
        andLikeParams: {...tableProps.requestParams.base, ...tableProps.requestParams.search}
      }),
      ...page
    });
    return result;
  },
  subCurrent(row) {
    listWrapperRef.value.assignSelected({edit: row});
  },
  title: t('views.rule.ruleLibrary.IndexPage.RuleTable.title'),
  columns: []
};
 
const listWrapperProps = {
  ref: listWrapperRef,
  title: t('views.rule.ruleLibrary.IndexPage.RuleTable.title'),
  complementHeight: 98,
};
 
const searchProps = {
  ref: tableSearchRef,
  formFields: [],
  subSubmit: (params) => {
    tableProps.requestParams.search = params;
    tableProRef.value.getTableData(true);
  }
}
 
const onOpenForm = (row) => {
  formDialogRef.value.onOpen(row, ['type_name', ...tableProps.columns.map(e => e.prop)]);
}
 
const onInit  = () => {
 
  tableProps.columns = columns.filter(e => codeColumns[tableProps.requestParams.base.type_code].includes(e.prop));
  searchProps.formFields = fields.filter(e => codeColumns[tableProps.requestParams.base.type_code].includes(e.prop));
 
  tableProRef.value.$forceUpdate(tableProps);
  tableSearchRef.value.$forceUpdate(searchProps);
 
  tableProps.requestParams.search = tableSearchRef.value.formFields.getModel();
  tableProRef.value.getTableData(true);
}
 
const onActive = async (active) => {
  tableProps.requestParams.base.type_code = active.code;
  listWrapperRef.value.assignSelected({add: {type_code: active.code, type_name: active.name}});
  onInit();
}
 
const onDelete = async (row) => {
  await modal.confirm("是否确认删除?");
 
  await entityStore.deleteEntity({
    dataName: 'sys_library_rule',
    id: row.id
  });
  tableProRef.value.getTableData(false);
};
 
 
defineExpose({
  /**
   * 初始化
   */
  onActive
});
 
</script>