|
@@ -0,0 +1,261 @@
|
|
|
+<template>
|
|
|
+ <div id="schedule">
|
|
|
+ <data-table
|
|
|
+ height="600px"
|
|
|
+ :fields="fields"
|
|
|
+ :data="list"
|
|
|
+ :opera="opera"
|
|
|
+ :total="total"
|
|
|
+ @query="search"
|
|
|
+ @delete="toDelete"
|
|
|
+ @edit="toEdit"
|
|
|
+ @disable="({ data }) => toDisable(data, '1')"
|
|
|
+ @able="({ data }) => toDisable(data, '0')"
|
|
|
+ >
|
|
|
+ <template #filterEnd>
|
|
|
+ <el-button type="primary" @click="toAdd">添加</el-button>
|
|
|
+ </template>
|
|
|
+ <template #custom="{item,row}">
|
|
|
+ <template v-if="item.model === 'table'"> {{ getProp(row, 'table') }} </template>
|
|
|
+ <template v-if="item.model === 'column'"> {{ getProp(row, 'column') }} </template>
|
|
|
+ <template v-if="item.model === 'limit'"> {{ row.number }}{{ getProp(row, 'unit') }} </template>
|
|
|
+ </template>
|
|
|
+ </data-table>
|
|
|
+ <el-dialog title="监控信息" :visible.sync="dialog" center width="40%">
|
|
|
+ <el-form>
|
|
|
+ <el-form-item label="表">
|
|
|
+ <el-select v-model="form.table">
|
|
|
+ <el-option v-for="(table, ti) in tableList" :key="`table${ti}`" :label="table.zh" :value="table.table"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="监控内容">
|
|
|
+ <el-select v-model="form.column">
|
|
|
+ <el-option v-for="(col, ti) in getColumnList(form.table)" :key="`table${ti}`" :label="col.label" :value="col.model"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="报警界限">
|
|
|
+ <el-input-number v-model="form.number" :min="0"></el-input-number>
|
|
|
+ <el-radio-group v-model="form.unit" style="padding-left:10px">
|
|
|
+ <el-radio v-for="(i, index) in periodList" :key="`p${index}`" :label="i.value">{{ i.label }}</el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="通知用户">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="6">
|
|
|
+ 可选择指定身份下的用户:
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="4" v-for="(i, index) in roleList" :key="`role${index}`">
|
|
|
+ <el-link type="primary" @click="selectUserByRole(i)" :underline="false">{{ i.name }}</el-link>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </el-col>
|
|
|
+ <el-checkbox-group v-model="form.user_ids">
|
|
|
+ <el-col :span="4" v-for="(i, index) in userList" :key="`user${index}`">
|
|
|
+ <el-checkbox :label="i._id">{{ i.name }}</el-checkbox>
|
|
|
+ </el-col>
|
|
|
+ </el-checkbox-group>
|
|
|
+ </el-row>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-row type="flex" justify="space-around">
|
|
|
+ <el-col :span="4">
|
|
|
+ <el-button type="primary" @click="toSave">保存计划</el-button>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </el-dialog>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import { mapState, createNamespacedHelpers } from 'vuex';
|
|
|
+const { mapActions: util } = createNamespacedHelpers('util');
|
|
|
+const { mapActions: user } = createNamespacedHelpers('user');
|
|
|
+const { mapActions: role } = createNamespacedHelpers('role');
|
|
|
+const { mapActions: schedule } = createNamespacedHelpers('schedule');
|
|
|
+export default {
|
|
|
+ name: 'schedule',
|
|
|
+ props: {},
|
|
|
+ components: {},
|
|
|
+ data: function() {
|
|
|
+ return {
|
|
|
+ dialog: false,
|
|
|
+ opera: [
|
|
|
+ {
|
|
|
+ label: '编辑',
|
|
|
+ method: 'edit',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '禁用',
|
|
|
+ type: 'info',
|
|
|
+ method: 'disable',
|
|
|
+ display: i => i.status === '0',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '使用',
|
|
|
+ type: 'success',
|
|
|
+ method: 'able',
|
|
|
+ display: i => i.status === '1',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ label: '删除',
|
|
|
+ confirm: true,
|
|
|
+ type: 'danger',
|
|
|
+ method: 'delete',
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ fields: [
|
|
|
+ { label: '表', model: 'table', custom: true },
|
|
|
+ { label: '项', model: 'column', custom: true },
|
|
|
+ { label: '报警界限', model: 'limit', custom: true },
|
|
|
+ {
|
|
|
+ label: '状态',
|
|
|
+ model: 'status',
|
|
|
+ filter: 'select',
|
|
|
+ type: 'select',
|
|
|
+ format: i => (i === '0' ? '使用' : '禁用'),
|
|
|
+ list: [
|
|
|
+ { label: '使用', value: '0' },
|
|
|
+ { label: '禁用', value: '1' },
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ periodList: [
|
|
|
+ { label: '天', value: 'd' },
|
|
|
+ { label: '月', value: 'M' },
|
|
|
+ { label: '年', value: 'y' },
|
|
|
+ ],
|
|
|
+ tableList: [],
|
|
|
+ statusList: [],
|
|
|
+ list: [],
|
|
|
+ total: 0,
|
|
|
+ form: {
|
|
|
+ user_ids: [],
|
|
|
+ },
|
|
|
+ roleList: [],
|
|
|
+ userList: [],
|
|
|
+ };
|
|
|
+ },
|
|
|
+ created() {
|
|
|
+ this.toGetModel();
|
|
|
+ this.search();
|
|
|
+ this.getOtherList();
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ ...schedule(['query', 'create', 'update', 'fetch', 'delete']),
|
|
|
+ ...role({ getRoleList: 'query' }),
|
|
|
+ ...user({ getUserList: 'query' }),
|
|
|
+ ...util(['getModel']),
|
|
|
+ async search({ skip = 0, limit = 10, ...info } = {}) {
|
|
|
+ const res = await this.query({ skip, limit, ...info });
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ const { data, total } = res;
|
|
|
+ this.$set(this, `list`, data);
|
|
|
+ this.$set(this, `total`, total);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async toSave() {
|
|
|
+ let duplicate = _.cloneDeep(this.form);
|
|
|
+ const { id } = this.form;
|
|
|
+ let res;
|
|
|
+ if (id) {
|
|
|
+ res = await this.update(duplicate);
|
|
|
+ } else {
|
|
|
+ res = await this.create(duplicate);
|
|
|
+ }
|
|
|
+ if (this.$checkRes(res, '保存成功', '保存失败')) {
|
|
|
+ this.toReturn();
|
|
|
+ this.search();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async toEdit({ data }) {
|
|
|
+ this.dialog = true;
|
|
|
+ this.$set(this, `form`, _.cloneDeep(data));
|
|
|
+ },
|
|
|
+ async toDelete({ data }) {
|
|
|
+ const res = await this.delete(data.id);
|
|
|
+ if (this.$checkRes(res, '删除成功')) {
|
|
|
+ this.search();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ // 修改状态
|
|
|
+ async toDisable(data, type) {
|
|
|
+ const dup = _.cloneDeep(data);
|
|
|
+ dup.status = type;
|
|
|
+ const res = await this.update(dup);
|
|
|
+ if (this.$checkRes(res, '状态修改成功', '状态修改失败')) {
|
|
|
+ this.search();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ getProp(data, model) {
|
|
|
+ if (model === 'unit') {
|
|
|
+ const res = this.periodList.find(f => f.value === data.unit);
|
|
|
+ if (res) return _.get(res, 'label', '');
|
|
|
+ }
|
|
|
+ const res = this.tableList.find(f => f.table === data.table);
|
|
|
+ if (!res) return '';
|
|
|
+ const { value, zh } = res;
|
|
|
+ if (model === 'table') return zh;
|
|
|
+ const cres = value.find(f => f.model === data.column);
|
|
|
+ if (cres) return _.get(cres, 'label', '');
|
|
|
+ },
|
|
|
+ getColumnList(table) {
|
|
|
+ let arr = [];
|
|
|
+ const model = this.tableList.find(f => f.table === table);
|
|
|
+ if (model) {
|
|
|
+ arr = _.get(model, 'value', []);
|
|
|
+ arr = arr.filter(f => f.type === 'date');
|
|
|
+ }
|
|
|
+ return arr;
|
|
|
+ },
|
|
|
+ // 根据role添加user_id至form.user_ids
|
|
|
+ selectUserByRole(role) {
|
|
|
+ const { type } = role;
|
|
|
+ let list = this.userList.filter(f => f.role === type);
|
|
|
+ list = list.map(i => i._id);
|
|
|
+ let dup = _.cloneDeep(this.form.user_ids);
|
|
|
+ dup = _.uniq([...dup, ...list]);
|
|
|
+ this.$set(this.form, `user_ids`, dup);
|
|
|
+ },
|
|
|
+ toAdd() {
|
|
|
+ this.dialog = true;
|
|
|
+ },
|
|
|
+ toReturn() {
|
|
|
+ this.dialog = false;
|
|
|
+ this.form = { user_ids: [] };
|
|
|
+ },
|
|
|
+ async toGetModel() {
|
|
|
+ let res = await this.getModel('all');
|
|
|
+ if (this.$checkRes(res)) {
|
|
|
+ let dup = _.cloneDeep(res);
|
|
|
+ dup = dup.map(t => {
|
|
|
+ t.value = t.value.filter(f => f.type === 'date');
|
|
|
+ if (t.value.length > 0) return t;
|
|
|
+ });
|
|
|
+ dup = _.compact(dup);
|
|
|
+ this.$set(this, `tableList`, dup);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async getOtherList() {
|
|
|
+ const roleRes = await this.getRoleList();
|
|
|
+ if (this.$checkRes(roleRes)) this.$set(this, `roleList`, roleRes.data);
|
|
|
+ const userRes = await this.getUserList();
|
|
|
+ if (this.$checkRes(userRes)) this.$set(this, `userList`, userRes.data);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ ...mapState(['user', 'menuParams']),
|
|
|
+ pageTitle() {
|
|
|
+ return `${this.$route.meta.title}`;
|
|
|
+ },
|
|
|
+ },
|
|
|
+ metaInfo() {
|
|
|
+ return { title: this.$route.meta.title };
|
|
|
+ },
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="less" scoped></style>
|