index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <div class="app-container" style="height: 100%; box-sizing: border-box; overflow-y: auto">
  3. <div class="mymain-container">
  4. <div class="btn-group clearfix">
  5. <div class="fl">
  6. <el-button size="small" type="primary" icon="el-icon-plus" @click="openFormWin('add', '0')"
  7. >添加菜单</el-button
  8. >
  9. </div>
  10. </div>
  11. <div class="table">
  12. <el-table
  13. v-loading="listLoading"
  14. :data="dataList"
  15. row-key="moduleId"
  16. border
  17. default-expand-all
  18. :tree-props="{ children: 'pages' }"
  19. >
  20. <el-table-column prop="moduleName" label="菜单名称" width="340px" />
  21. <el-table-column prop="code" label="code" width="260px" />
  22. <el-table-column align="center" prop="status" label="状态" width="80px">
  23. <template slot-scope="scope">
  24. <span>{{ ['显示', '不显示'][[true, false].indexOf(scope.row.status)] || '' }}</span>
  25. </template>
  26. </el-table-column>
  27. <el-table-column prop="remark" label="描述" />
  28. <el-table-column align="right" label="操作" width="150" fixed="right">
  29. <template slot-scope="scope">
  30. <el-button
  31. type="primary"
  32. size="mini"
  33. icon="el-icon-plus"
  34. @click="openFormWin('add', scope.row.moduleId)"
  35. />
  36. <el-button
  37. type="primary"
  38. size="mini"
  39. icon="el-icon-edit"
  40. @click="openFormWin('edit', scope.row.moduleId)"
  41. />
  42. <el-popconfirm style="margin-left: 10px" title="确定删除吗?" @confirm="handleDelete(scope.row.moduleId)">
  43. <el-button slot="reference" size="mini" icon="el-icon-delete" />
  44. </el-popconfirm>
  45. </template>
  46. </el-table-column>
  47. </el-table>
  48. </div>
  49. </div>
  50. <!-- 创建编辑菜单 -->
  51. <div class="cartographer_big">
  52. <el-dialog
  53. :title="this.menuFormData.moduleId ? '编辑菜单' : '创建菜单'"
  54. width="100%"
  55. :modal="false"
  56. :visible.sync="menuFormBool"
  57. :before-close="cancelFormWin"
  58. :close-on-click-modal="false"
  59. >
  60. <zj-page-container v-if="menuFormBool">
  61. <zj-page-fill class="neibuviewaaaaa">
  62. <zj-form-container
  63. ref="formRef"
  64. :form-data="menuFormData"
  65. :form-attributes="{ size: 'medium' }"
  66. :styleSwitch="false"
  67. >
  68. <zj-form-module
  69. title="基本信息"
  70. :form-data="menuFormData"
  71. :form-items="basicInfo"
  72. :showHade="false"
  73. label-width="120px"
  74. />
  75. </zj-form-container>
  76. </zj-page-fill>
  77. <div>
  78. <div style="box-sizing: border-box; padding: 10px 60px; text-align: right">
  79. <el-button @click="cancelFormWin">取 消</el-button>
  80. <el-button type="primary" @click="submitMenuForm">确 定</el-button>
  81. </div>
  82. </div>
  83. </zj-page-container>
  84. </el-dialog>
  85. </div>
  86. </div>
  87. </template>
  88. <script>
  89. import { mapGetters } from 'vuex'
  90. import { getToken } from '@/utils/auth'
  91. import { getMenuList, addMenu, editMenu, deleteMenu, getMenuDetail } from '@/api/miniMenus'
  92. import iconList from '@/const/iconList.js'
  93. export default {
  94. data() {
  95. return {
  96. dataList: [], // 列表数据
  97. listLoading: true, // 列表加载loading
  98. isChooseIconDialog: false,
  99. iconList: iconList,
  100. menuTypeList: [
  101. {
  102. value: 1,
  103. label: '服务产品'
  104. },
  105. {
  106. value: 2,
  107. label: '页面'
  108. },
  109. {
  110. value: 4,
  111. label: '模块'
  112. }
  113. ],
  114. menuFormData: {
  115. parentId: '',
  116. moduleId: '',
  117. moduleName: '',
  118. code: '',
  119. type: 1,
  120. status: true,
  121. remark: '',
  122. url: '',
  123. fullUrl: '',
  124. icon: '',
  125. sortNum: 0,
  126. flag: '',
  127. isCache: 1,
  128. childList: []
  129. },
  130. menuFormBool: false
  131. }
  132. },
  133. computed: {
  134. ...mapGetters(['userid', 'name']),
  135. basicInfo() {
  136. return [
  137. {
  138. name: 'el-radio',
  139. md: 24,
  140. options: this.menuTypeList,
  141. attributes: {
  142. placeholder: '请选择'
  143. },
  144. formItemAttributes: {
  145. label: '类型',
  146. prop: 'type'
  147. }
  148. },
  149. {
  150. name: 'el-cascader',
  151. md: 24,
  152. attributes: {
  153. placeholder: '请选择',
  154. options: [{ moduleId: '0', moduleName: '设定一级' }, ...this.dataList],
  155. props: { checkStrictly: true, value: 'moduleId', label: 'moduleName', emitPath: false },
  156. filterable: true,
  157. clearable: true,
  158. style: { width: '100%' }
  159. },
  160. formItemAttributes: {
  161. label: '上级',
  162. prop: 'parentId'
  163. }
  164. },
  165. {
  166. name: 'el-input',
  167. md: 24,
  168. attributes: {
  169. placeholder: '请输入菜单名称'
  170. },
  171. formItemAttributes: {
  172. label: '菜单名称',
  173. prop: 'moduleName',
  174. rules: [{ required: true, message: '请选择类型', trigger: 'blur' }]
  175. }
  176. },
  177. {
  178. name: 'el-input',
  179. md: 24,
  180. attributes: {
  181. placeholder: '请输入CODE'
  182. },
  183. formItemAttributes: {
  184. label: 'CODE',
  185. prop: 'code',
  186. rules: [{ required: true, message: '请选择类型', trigger: 'blur' }]
  187. }
  188. },
  189. {
  190. name: 'el-input',
  191. md: 24,
  192. attributes: {
  193. type: 'textarea',
  194. rows: 3,
  195. placeholder: '请输入'
  196. },
  197. formItemAttributes: {
  198. label: '备注',
  199. prop: 'remark',
  200. rules: []
  201. }
  202. },
  203. {
  204. name: 'el-switch',
  205. md: 24,
  206. attributes: {
  207. 'active-value': true,
  208. 'inactive-value': false,
  209. 'active-color': '#13ce66',
  210. 'inactive-color': '#ff4949'
  211. },
  212. formItemAttributes: {
  213. label: '是否显示',
  214. prop: 'status'
  215. }
  216. }
  217. ]
  218. }
  219. },
  220. created() {
  221. this.getList()
  222. },
  223. methods: {
  224. // 获取菜单列表
  225. getList() {
  226. this.listLoading = true
  227. getMenuList({
  228. adminUserId: this.userid,
  229. flag: 'menu'
  230. })
  231. .then(res => {
  232. this.dataList = this.recursionFn(res.data)
  233. })
  234. .finally(() => {
  235. this.listLoading = false
  236. })
  237. },
  238. // 组合数据
  239. recursionFn(arr) {
  240. if (!arr.length) return []
  241. for (let i = 0; i < arr.length; i++) {
  242. if (arr[i].children.length) {
  243. arr[i].pages = []
  244. arr[i].controls = []
  245. for (let j = 0; j < arr[i].children.length; j++) {
  246. if ([1, 2, 4].includes(arr[i].children[j].type)) {
  247. arr[i].pages.push(arr[i].children[j])
  248. }
  249. if ([3].includes(arr[i].children[j].type)) {
  250. arr[i].controls.push(arr[i].children[j])
  251. }
  252. }
  253. this.recursionFn(arr[i].children)
  254. }
  255. }
  256. return arr || []
  257. },
  258. // 打开 新增编辑
  259. openFormWin(type, cid) {
  260. if (type == 'add') {
  261. this.menuFormData.parentId = cid
  262. this.menuFormBool = true
  263. } else if (type == 'edit') {
  264. getMenuDetail({ moduleId: cid }).then(res => {
  265. this.menuFormData = {
  266. ...res.data
  267. }
  268. this.menuFormBool = true
  269. })
  270. }
  271. },
  272. // 关闭窗口
  273. cancelFormWin() {
  274. this.$data.menuFormData = this.$options.data().menuFormData
  275. this.$refs?.formRef?.resetFields()
  276. this.menuFormBool = false
  277. },
  278. // 提交菜单
  279. submitMenuForm() {
  280. this.$refs.formRef.validate(valid => {
  281. if (valid) {
  282. if (this.menuFormData.moduleId) {
  283. editMenu(this.menuFormData).then(res => {
  284. this.getList()
  285. this.cancelFormWin()
  286. this.$successMsg('编辑成功')
  287. })
  288. } else {
  289. addMenu(this.menuFormData).then(res => {
  290. this.getList()
  291. this.cancelFormWin()
  292. this.$successMsg('添加成功')
  293. })
  294. }
  295. }
  296. })
  297. },
  298. // 操作 - 删除
  299. handleDelete(id) {
  300. deleteMenu({ id: id }).then(res => {
  301. this.getList()
  302. this.$successMsg()
  303. })
  304. }
  305. }
  306. }
  307. </script>
  308. <style scoped lang="scss">
  309. .iconList {
  310. display: flex;
  311. flex-wrap: wrap;
  312. max-height: 40vh;
  313. overflow-y: scroll;
  314. .item {
  315. width: 40px;
  316. height: 40px;
  317. text-align: center;
  318. line-height: 40px;
  319. cursor: pointer;
  320. i {
  321. font-size: 18px;
  322. }
  323. &:hover {
  324. background: #f5f5f5;
  325. i {
  326. color: #409eff;
  327. }
  328. }
  329. }
  330. }
  331. ::v-deep .iconInput {
  332. display: flex;
  333. .icon {
  334. margin-right: 10px;
  335. border-radius: 4px;
  336. border: 1px solid #dcdfe6;
  337. box-sizing: border-box;
  338. color: #606266;
  339. width: 40px;
  340. height: 40px;
  341. text-align: center;
  342. line-height: 40px;
  343. flex-shrink: 0;
  344. i {
  345. font-size: 18px;
  346. }
  347. }
  348. input {
  349. flex: 1;
  350. }
  351. button {
  352. margin-left: 10px;
  353. }
  354. }
  355. </style>
  356. <style lang="scss">
  357. .el-image-viewer__wrapper .el-icon-circle-close {
  358. color: #ffffff !important;
  359. font-size: 60px;
  360. }
  361. .el-table__row.expanded {
  362. background: #f5f5f5;
  363. }
  364. .neibuviewaaaaa {
  365. .zj-page-fill-scroll {
  366. box-sizing: border-box;
  367. padding: 20px 50px;
  368. }
  369. }
  370. </style>