Quellcode durchsuchen

@zengqiao@菜单

HexOr vor 3 Jahren
Ursprung
Commit
3c8ff915e4

+ 12 - 0
dmp-edge-ai/src/service/MenuService.js

@ -57,3 +57,15 @@ export function deleteMenu(menuId) {
57 57
    method: 'get'
58 58
  })
59 59
}
60
61
/**
62
 * 修改状态
63
 * @param userId
64
 */
65
export function changeStatus(data) {
66
  return request({
67
    url: `/menu/changeStatus`,
68
    method: 'post',
69
    data
70
  })
71
}

+ 3 - 3
dmp-edge-ai/src/utils/constant.js

@ -23,9 +23,9 @@ export const VisibleStatus = createEnum({
23 23
 * @type {{getDescFromValue, options, getDesc}}
24 24
 */
25 25
export const MenuType = createEnum({
26
  CONTENT: [1, '目录'],
27
  MENU: [0, '菜单'],
28
  BUTTON: [2, '按钮']
26
  CONTENT: ['1', '目录'],
27
  MENU: ['0', '菜单'],
28
  BUTTON: ['2', '按钮']
29 29
})
30 30
31 31
/**

+ 200 - 0
dmp-edge-ai/src/views/system/menu/components/BaseDialog.vue

@ -0,0 +1,200 @@
1
<template>
2
  <el-dialog :title="title" class="common-modal" :visible.sync="dialogVisible" width="68.75%" @open="initData">
3
    <el-form ref="form" :model="form" :rules="rules" label-width="100px">
4
      <el-row>
5
        <el-col :span="10" :offset="2">
6
          <el-row>
7
            <el-col>
8
              <el-form-item label="菜单名称" prop="menuName">
9
                <el-input v-model.trim="form.menuName" placeholder="请输入菜单名称"></el-input>
10
              </el-form-item>
11
              <el-form-item label="菜单类型" prop="menuType">
12
                <el-radio-group v-model="form.menuType">
13
                  <el-radio v-for="item in MenuType.options" :key="'type' + item[0]" :label="item[0]">
14
                    {{ item[1] }}
15
                  </el-radio>
16
                </el-radio-group>
17
              </el-form-item>
18
              <el-form-item label="内外链地址" prop="linkUrl" v-if="form.menuType === MenuType.MENU">
19
                <el-input v-model.trim="form.linkUrl" placeholder="请输入内外链地址"></el-input>
20
              </el-form-item>
21
              <el-form-item label="排序" prop="menuSort">
22
                <el-input-number v-model="form.menuSort" :min="1"></el-input-number>
23
              </el-form-item>
24
            </el-col>
25
          </el-row>
26
        </el-col>
27
        <el-col :span="10">
28
          <el-row>
29
            <el-col>
30
              <el-form-item label="上级菜单" prop="parentOrganizeId">
31
                <el-select
32
                  v-model="form.parentMenuId"
33
                  style="width: 100%"
34
                  clearable
35
                  :disabled="modalType === ModalType.EDIT"
36
                >
37
                  <el-option v-for="item in content" :key="item.menuId" :label="item.menuName" :value="item.menuId">
38
                  </el-option>
39
                </el-select>
40
              </el-form-item>
41
              <el-form-item label="打开方式" prop="iframeFlag" v-if="form.menuType === MenuType.MENU">
42
                <el-radio-group v-model="form.iframeFlag">
43
                  <el-radio v-for="item in IframeFlag.options" :key="'iframe' + item[0]" :label="item[0]">
44
                    {{ item[1] }}
45
                  </el-radio>
46
                </el-radio-group>
47
              </el-form-item>
48
              <el-form-item label="图标" prop="menuIcon" v-if="form.menuType === MenuType.CONTENT">
49
                <el-input v-model.trim="form.menuIcon" placeholder="请选择或输入图标">
50
                  <el-button slot="append" icon="el-icon-setting"></el-button>
51
                </el-input>
52
              </el-form-item>
53
              <el-form-item label="是否可见" prop="hiddenFlag">
54
                <el-radio-group v-model="form.hiddenFlag">
55
                  <el-radio v-for="item in VisibleStatus.options" :key="'status' + item[0]" :label="item[0]">
56
                    {{ item[1] }}
57
                  </el-radio>
58
                </el-radio-group>
59
              </el-form-item>
60
            </el-col>
61
          </el-row>
62
        </el-col>
63
      </el-row>
64
    </el-form>
65
    <span slot="footer" class="dialog-footer">
66
      <el-button v-if="!submitLoading" type="primary" @click="submit(modalType)">提交</el-button>
67
      <el-button v-else type="primary" :loading="submitLoading">提交中</el-button>
68
      <el-button @click="dialogVisible = false">关闭并返回</el-button>
69
    </span>
70
  </el-dialog>
71
</template>
72
73
<script>
74
import * as MenuService from '@/service/MenuService'
75
import { ModalType, VisibleStatus, MenuType, IframeFlag } from '@/utils/constant'
76
export default {
77
  name: 'BaseDialog',
78
  props: {
79
    menuId: {
80
      type: [Number, String]
81
    },
82
    show: {
83
      type: Boolean,
84
      required: true,
85
      default: false
86
    },
87
    menuList: {
88
      type: Array,
89
      required: true,
90
      default: () => []
91
    }
92
  },
93
  data() {
94
    this.VisibleStatus = VisibleStatus
95
    this.MenuType = MenuType
96
    this.IframeFlag = IframeFlag
97
    this.ModalType = ModalType
98
    // 组织树形下拉组件映射配置
99
    this.selectTreeConfig = {
100
      id: 'menuId',
101
      label: 'menuName',
102
      children: 'children'
103
    }
104
    return {
105
      form: {
106
        menuName: '',
107
        menuType: '',
108
        parentMenuId: '',
109
        iframeFlag: '',
110
        linkUrl: '',
111
        menuIcon: '',
112
        menuSort: '1',
113
        hiddenFlag: VisibleStatus.YES
114
      },
115
      rules: {
116
        menuName: [{ required: true, message: '请输入菜单名称', trigger: 'blur' }],
117
        menuType: [{ required: true, message: '请选择菜单类型', trigger: 'change' }],
118
        iframeFlag: [{ required: true, message: '请选择打开方式', trigger: 'change' }],
119
        linkUrl: [{ required: true, message: '请输入内外链地址', trigger: 'change' }],
120
        menuIcon: [{ required: true, message: '请选择或输入图标', trigger: 'blur' }]
121
      },
122
      modalType: ModalType.ADD,
123
      submitLoading: false
124
    }
125
  },
126
  computed: {
127
    dialogVisible: {
128
      set(val) {
129
        this.$emit('update:show', val)
130
      },
131
      get() {
132
        return this.show
133
      }
134
    },
135
    title() {
136
      return this.modalType === ModalType.ADD ? '新增菜单' : '编辑菜单'
137
    },
138
    content() {
139
      return this.menuList.filter((item) => item.menuType === MenuType.CONTENT)
140
    }
141
  },
142
  methods: {
143
    /**
144
     * 初始化模态框
145
     */
146
    initData() {
147
      this.$refs.form && this.$refs.form.resetFields()
148
      this.form = {
149
        menuName: '',
150
        menuType: '',
151
        parentMenuId: '',
152
        iframeFlag: '',
153
        linkUrl: '',
154
        menuIcon: '',
155
        menuSort: '1',
156
        hiddenFlag: VisibleStatus.YES
157
      }
158
      if (this.menuId) {
159
        // 编辑
160
        this.modalType = ModalType.EDIT
161
        MenuService.getMenuInfo(this.menuId).then((res) => {
162
          this.form = { ...res, ...{ parentMenuId: res.parentMenuId === '0' ? '' : res.parentMenuId } }
163
          Reflect.deleteProperty(this.form, 'createDate')
164
          Reflect.deleteProperty(this.form, 'doneDate')
165
        })
166
      } else {
167
        // 新增
168
        this.modalType = ModalType.ADD
169
      }
170
    },
171
    submit(type) {
172
      this.$refs['form'].validate(async (valid) => {
173
        if (!valid) {
174
          return
175
        }
176
        const params = { ...this.form }
177
        if (this.form.parentMenuId === '') {
178
          params.parentMenuId = '0'
179
        }
180
        this.submitLoading = true
181
        try {
182
          if (type === ModalType.ADD) {
183
            // 新增
184
            await MenuService.add(params)
185
          } else {
186
            // 编辑
187
            await MenuService.edit(params)
188
          }
189
          this.dialogVisible = false
190
          this.$emit('refresh')
191
        } finally {
192
          this.submitLoading = false
193
        }
194
      })
195
    }
196
  }
197
}
198
</script>
199
200
<style scoped lang="scss"></style>

+ 65 - 20
dmp-edge-ai/src/views/system/menu/index.vue

@ -23,14 +23,7 @@
23 23
        <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
24 24
      </div>
25 25
26
      <el-table
27
        :data="tableData"
28
        border
29
        row-key="menuId"
30
        default-expand-all
31
        :header-cell-style="headerStyle"
32
        @selection-change="handleSelectionChange"
33
      >
26
      <el-table :data="tableData" border row-key="menuId" default-expand-all :header-cell-style="headerStyle">
34 27
        <el-table-column type="selection" width="55"></el-table-column>
35 28
        <el-table-column label="菜单名称" prop="menuName" width="180"></el-table-column>
36 29
        <el-table-column label="菜单类型" prop="menuType" width="80">
@ -54,8 +47,8 @@
54 47
          </template>
55 48
        </el-table-column>
56 49
        <el-table-column label="操作" width="180">
57
          <template slot-scope="{ row }">
58
            <a class="table-option" @click="changeState(row)">
50
          <template slot-scope="{ row, $index }">
51
            <a class="table-option" @click="changeState(row, $index)">
59 52
              {{ row.hiddenFlag === VisibleStatus.YES ? VisibleStatus.getDesc('NO') : VisibleStatus.getDesc('YES') }}
60 53
            </a>
61 54
            <a class="table-option" @click="edit(row)">编辑</a>
@ -64,6 +57,8 @@
64 57
        </el-table-column>
65 58
      </el-table>
66 59
    </div>
60
    <!--新建/编辑菜单模态框-->
61
    <base-dialog :show.sync="baseVisible" :menuId="menuId" :menuList="tableData" @refresh="search"> </base-dialog>
67 62
  </div>
68 63
</template>
69 64
@ -74,7 +69,8 @@ import { VisibleStatus, MenuType, IframeFlag } from '@/utils/constant'
74 69
export default {
75 70
  name: 'Menu',
76 71
  components: {
77
    PageHeader
72
    PageHeader,
73
    BaseDialog: () => import('./components/BaseDialog')
78 74
  },
79 75
  data() {
80 76
    this.VisibleStatus = VisibleStatus
@ -91,24 +87,73 @@ export default {
91 87
        menuType: '',
92 88
        hiddenFlag: ''
93 89
      },
94
      tableData: []
90
      tableData: [],
91
      menuId: '',
92
      baseVisible: false
95 93
    }
96 94
  },
97 95
  methods: {
98 96
    addMenu() {
99
      console.log(111)
97
      this.menuId = ''
98
      this.baseVisible = true
100 99
    },
101
    changeState(row) {
102
      console.log(row.status)
100
    changeState(row, index) {
101
      const { menuId, hiddenFlag } = row
102
      const text = hiddenFlag === VisibleStatus.YES ? VisibleStatus.getDesc('NO') : VisibleStatus.getDesc('YES')
103
      this.$confirm(`您确定${text}该菜单吗?`, '提示', {
104
        confirmButtonText: '确定',
105
        cancelButtonText: '取消',
106
        type: 'warning',
107
        beforeClose: (action, instance, done) => {
108
          if (action === 'confirm') {
109
            instance.confirmButtonLoading = true
110
            instance.confirmButtonText = '执行中...'
111
            const params = {
112
              menuId,
113
              hiddenFlag: hiddenFlag === VisibleStatus.YES ? VisibleStatus.NO : VisibleStatus.YES
114
            }
115
            MenuService.changeStatus(params)
116
              .then(() => {
117
                this.tableData[index].hiddenFlag = params.hiddenFlag
118
                done()
119
              })
120
              .finally(() => {
121
                instance.confirmButtonText = '确定'
122
                instance.confirmButtonLoading = false
123
              })
124
          } else {
125
            done()
126
          }
127
        }
128
      })
103 129
    },
104 130
    edit(row) {
105
      console.log(row)
131
      this.menuId = row.menuId
132
      this.baseVisible = true
106 133
    },
107 134
    deleteItem(row) {
108
      console.log(row)
109
    },
110
    handleSelectionChange(val) {
111
      console.log(val)
135
      this.$confirm(`您确定删除该菜单吗?`, '提示', {
136
        confirmButtonText: '确定',
137
        cancelButtonText: '取消',
138
        type: 'warning',
139
        beforeClose: (action, instance, done) => {
140
          if (action === 'confirm') {
141
            instance.confirmButtonLoading = true
142
            instance.confirmButtonText = '删除中...'
143
            MenuService.deleteMenu(row.menuId)
144
              .then(() => {
145
                this.search()
146
                done()
147
              })
148
              .finally(() => {
149
                instance.confirmButtonText = '确定'
150
                instance.confirmButtonLoading = false
151
              })
152
          } else {
153
            done()
154
          }
155
        }
156
      })
112 157
    },
113 158
    search() {
114 159
      this.getMenuList()

+ 1 - 1
dmp-edge-ai/src/views/system/organize/components/BaseDialog.vue

@ -111,7 +111,7 @@ export default {
111 111
      }
112 112
    },
113 113
    title() {
114
      return this.modalType === ModalType.ADD ? '新增角色' : '编辑角色'
114
      return this.modalType === ModalType.ADD ? '新增部门' : '编辑部门'
115 115
    }
116 116
  },
117 117
  methods: {