index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never" v-loading="loading">
  4. <matter-search @search="reload"> </matter-search>
  5. <!-- 数据表格 -->
  6. <ele-pro-table
  7. ref="table"
  8. :columns="columns"
  9. :datasource="datasource"
  10. :page-size="pageSize"
  11. @columns-change="handleColumnChange"
  12. :cache-key="cacheKeyUrl"
  13. @filter-change="selectType"
  14. >
  15. <!-- 表头工具栏 -->
  16. <template v-slot:toolbar>
  17. <el-button
  18. size="small"
  19. type="primary"
  20. icon="el-icon-plus"
  21. class="ele-btn-icon"
  22. @click="openEdit('add')"
  23. v-if="$hasPermission('main:warnrule:save')"
  24. >
  25. 新建
  26. </el-button>
  27. </template>
  28. <!-- 编码列 -->
  29. <template v-slot:ruleCode="{ row }">
  30. <el-link type="primary" :underline="false" @click="goDetail(row)">
  31. {{ row.ruleCode }}
  32. </el-link>
  33. </template>
  34. <template v-slot:alertCycleValue="{ row }">
  35. <span v-if="row.alertCycleValue">{{ row.alertCycleValue }}</span>
  36. <template v-if="row.alertCycleUnit">
  37. <span v-for="(value, key) in cycleUnitOpt">
  38. <span v-if="key == row.alertCycleUnit">{{ value }}</span>
  39. </span>
  40. </template>
  41. </template>
  42. <!-- 操作列 -->
  43. <template v-slot:action="{ row }">
  44. <el-link
  45. type="primary"
  46. :underline="false"
  47. icon="el-icon-finished"
  48. @click="openEdit('clone', row)"
  49. v-if="$hasPermission('main:warnrule:update')"
  50. >
  51. 克隆
  52. </el-link>
  53. <el-link
  54. type="primary"
  55. :underline="false"
  56. icon="el-icon-edit"
  57. @click="openEdit('edit', row)"
  58. v-if="$hasPermission('main:warnrule:update')"
  59. >
  60. 修改
  61. </el-link>
  62. <el-popconfirm
  63. class="ele-action"
  64. title="确定要删除此角色吗?"
  65. @confirm="remove(row)"
  66. v-if="$hasPermission('main:warnrule:delete')"
  67. >
  68. <template v-slot:reference>
  69. <el-link type="danger" :underline="false" icon="el-icon-delete">
  70. 删除
  71. </el-link>
  72. </template>
  73. </el-popconfirm>
  74. </template>
  75. </ele-pro-table>
  76. </el-card>
  77. <!-- 新建或编辑弹窗 -->
  78. <matter-add
  79. ref="addMatterRulesRef"
  80. :pageType="pageType"
  81. :dialogTitle="dialogTitle"
  82. @done="reload"
  83. />
  84. </div>
  85. </template>
  86. <script>
  87. import tabMixins from '@/mixins/tableColumnsMixin';
  88. import MatterSearch from './components/matter-search.vue';
  89. import MatterAdd from './components/matter-add.vue';
  90. import {
  91. getList,
  92. getDetail,
  93. removeRule,
  94. listAllDateUnit
  95. } from '@/api/ruleManagement/earlyWarning';
  96. import dictMixins from '@/mixins/dictMixins';
  97. export default {
  98. mixins: [dictMixins, tabMixins],
  99. components: {
  100. MatterSearch,
  101. MatterAdd
  102. },
  103. data() {
  104. return {
  105. // 表格列配置
  106. columns: [
  107. {
  108. columnKey: 'index',
  109. label: '序号',
  110. type: 'index',
  111. width: 55,
  112. align: 'center',
  113. showOverflowTooltip: true,
  114. fixed: 'left'
  115. },
  116. {
  117. prop: 'ruleCode',
  118. label: '规则编码',
  119. align: 'center',
  120. showOverflowTooltip: true,
  121. minWidth: 110,
  122. slot: 'ruleCode'
  123. },
  124. {
  125. prop: 'ruleName',
  126. label: '规则名称',
  127. align: 'center',
  128. showOverflowTooltip: true,
  129. minWidth: 110
  130. },
  131. {//修改此prop名称时,请同步修改columnKey属性和下方selectType方法
  132. prop: 'enabled',
  133. label: '状态',
  134. align: 'center',
  135. showOverflowTooltip: true,
  136. minWidth: 110,
  137. formatter: (_row, _column, cellValue) => {
  138. return this.getDictValue('规则状态', _row.enabled);
  139. },
  140. filters: [
  141. { value: 1, text: '生效' },
  142. { value: 0, text: '失效' },
  143. ],
  144. filterMultiple: false,
  145. columnKey: 'enabled'
  146. },
  147. {
  148. prop: 'alertCycleValue',
  149. label: '周期',
  150. align: 'center',
  151. showOverflowTooltip: true,
  152. minWidth: 110,
  153. slot: 'alertCycleValue'
  154. },
  155. {
  156. prop: 'createUserName',
  157. label: '创建人',
  158. align: 'center',
  159. showOverflowTooltip: true,
  160. minWidth: 110
  161. },
  162. {
  163. prop: 'createTime',
  164. label: '创建时间',
  165. align: 'center',
  166. showOverflowTooltip: true,
  167. minWidth: 110,
  168. formatter: (_row, _column, cellValue) => {
  169. return this.$util.toDateString(cellValue);
  170. }
  171. },
  172. {
  173. columnKey: 'action',
  174. label: '操作',
  175. width: 230,
  176. align: 'center',
  177. resizable: false,
  178. slot: 'action',
  179. showOverflowTooltip: true
  180. }
  181. ],
  182. // 加载状态
  183. loading: false,
  184. pageType: 'add',
  185. dialogTitle: '',
  186. cycleUnitOpt: {},
  187. pageSize: this.$store.state.tablePageSize,
  188. cacheKeyUrl: 'dfb89646-rulesManagement-earlyWarningRules'
  189. };
  190. },
  191. computed: {},
  192. created() {
  193. // this.requestDict('规则周期');
  194. this.requestDict('预警类型');
  195. this.requestDict('规则状态');
  196. this.getData();
  197. },
  198. methods: {
  199. selectType(value) {
  200. let where = {}
  201. if (value.enabled.length > 0) {
  202. where['enabled'] = value.enabled[0]
  203. }
  204. this.reload(where)
  205. },
  206. /* 表格数据源 */
  207. datasource({ page, limit, where, order }) {
  208. return getList({ pageNum: page, size: limit, ...where });
  209. },
  210. /* 刷新表格 */
  211. reload(where) {
  212. this.$refs.table.reload({ page: 1, where });
  213. },
  214. async getData() {
  215. const res2 = await listAllDateUnit();
  216. this.cycleUnitOpt = res2;
  217. },
  218. remove(row) {
  219. removeRule([row.id]).then((res) => {
  220. this.$message.success('删除成功!');
  221. this.reload();
  222. });
  223. },
  224. openEdit(type, row) {
  225. this.pageType = type;
  226. this.dialogTitle =
  227. type == 'add' ? '新建规则' : type == 'edit' ? '编辑规则' : '克隆规则';
  228. this.$refs.addMatterRulesRef.openDialog(row, type);
  229. },
  230. goDetail({ id }) {
  231. this.$router.push({
  232. path: '/rulesManagement/earlyWarningRules/details',
  233. query: { id }
  234. });
  235. }
  236. }
  237. };
  238. </script>
  239. <style lang="scss" scoped></style>