index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <template>
  2. <div class="app-container">
  3. <div class="app-container">
  4. <div class="filter-container">
  5. <el-button class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="form_add">
  6. 新增
  7. </el-button>
  8. </div>
  9. <el-table
  10. v-loading="listLoading"
  11. element-loading-text="给我一点时间"
  12. :data="list"
  13. border
  14. fit
  15. highlight-current-row
  16. style="width: 100%;"
  17. :row-style="rowStyle"
  18. :cell-style="cellStyle"
  19. class="elTable"
  20. row-key="id"
  21. :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
  22. @sort-change="tableSort"
  23. >
  24. <el-table-column label="菜单名称" header-align="center" width="180px">
  25. <template slot-scope="scope">
  26. <el-tag :type="scope.row.menutype | menutypeFilter" size="small">
  27. <span>{{ scope.row.name }}</span>
  28. </el-tag>
  29. </template>
  30. </el-table-column>
  31. <el-table-column label="标题" width="140px" header-align="center" align="center">
  32. <template slot-scope="scope">
  33. <span>{{ scope.row.title }}</span>
  34. </template>
  35. </el-table-column>
  36. <el-table-column label="路径" width="100px" header-align="center" align="center">
  37. <template slot-scope="scope">
  38. <span>{{ scope.row.path }}</span>
  39. </template>
  40. </el-table-column>
  41. <el-table-column label="组件" min-width="150px" header-align="center" align="center">
  42. <template slot-scope="scope">
  43. <span>{{ scope.row.component }}</span>
  44. </template>
  45. </el-table-column>
  46. <el-table-column label="图标" width="100px" header-align="center" align="center">
  47. <template slot-scope="scope">
  48. <span>{{ scope.row.icon }}</span>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="重定向" width="100px" header-align="center" align="center">
  52. <template slot-scope="scope">
  53. <span>{{ scope.row.redirect }}</span>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="顺序" sortable prop="sort" width="100px" header-align="center" align="center">
  57. <template slot-scope="scope">
  58. <span>{{ scope.row.sort }}</span>
  59. </template>
  60. </el-table-column>
  61. <el-table-column label="启用" min-width="80px" header-align="center" align="center">
  62. <template slot-scope="scope">
  63. <el-switch
  64. v-model="scope.row.enable"
  65. active-color="#13ce66"
  66. inactive-color="#ff4949"
  67. :active-value="1"
  68. :inactive-value="0"
  69. @change="handleEnableChange(scope.$index, scope.row)"
  70. />
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="操作" header-align="center" align="center" width="260" class-name="small-padding fixed-width" fixed="right">
  74. <template slot-scope="{row}">
  75. <el-button type="primary" size="mini" @click="form_edit(row)">
  76. 编辑
  77. </el-button>
  78. <el-button v-if="row.status!='已删'" size="mini" type="danger" @click="form_delete(row)">
  79. 删除
  80. </el-button>
  81. </template>
  82. </el-table-column>
  83. </el-table>
  84. <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
  85. <el-form ref="dataForm" :rules="rules" :model="deptform" label-position="left" label-width="100px" style="width: 400px; margin-left:50px;">
  86. <el-form-item label="上级菜单" prop="parentid">
  87. <tree-select
  88. :disabled="disabled"
  89. :height="280"
  90. :width="200"
  91. size="small"
  92. :data="parent"
  93. :default-props="defaultProps"
  94. clearable
  95. :node-key="nodeKey"
  96. :checked-keys="defaultCheckedKeys"
  97. @popoverHide="popoverHide"
  98. />
  99. </el-form-item>
  100. <el-form-item label="菜单名称" prop="name">
  101. <el-input
  102. ref="name"
  103. v-model="deptform.name"
  104. />
  105. </el-form-item>
  106. <el-form-item label="类型" prop="menutype">
  107. <el-radio-group ref="menutype" v-model="deptform.menutype" @change="menutypechange">
  108. <el-radio label="menu">菜单</el-radio>
  109. <el-radio label="button">按钮</el-radio>
  110. </el-radio-group>
  111. </el-form-item>
  112. <el-form-item label="标题" prop="title">
  113. <el-input
  114. ref="title"
  115. v-model="deptform.title"
  116. />
  117. </el-form-item>
  118. <el-form-item label="路径" prop="path">
  119. <el-input
  120. ref="path"
  121. v-model="deptform.path"
  122. />
  123. </el-form-item>
  124. <el-form-item v-if="deptform.menutype==='menu'" label="组件" prop="component">
  125. <el-input
  126. ref="component"
  127. v-model="deptform.component"
  128. />
  129. </el-form-item>
  130. <el-form-item v-if="deptform.menutype==='menu'" label="图标" prop="icon">
  131. <el-input
  132. ref="icon"
  133. v-model="deptform.icon"
  134. />
  135. </el-form-item>
  136. <el-form-item v-if="deptform.menutype==='menu'" label="重定向" prop="redirect">
  137. <el-input
  138. ref="redirect"
  139. v-model="deptform.redirect"
  140. />
  141. </el-form-item>
  142. <el-form-item label="顺序" prop="sort">
  143. <el-input
  144. ref="sort"
  145. v-model="deptform.sort"
  146. />
  147. </el-form-item>
  148. <el-form-item label="启用" prop="enable">
  149. <el-switch
  150. ref="enable"
  151. v-model="deptform.enable"
  152. active-color="#13ce66"
  153. inactive-color="#ff4949"
  154. :active-value="1"
  155. :inactive-value="0"
  156. />
  157. </el-form-item>
  158. </el-form>
  159. <div slot="footer" class="dialog-footer">
  160. <el-button
  161. v-if="dialogStatus==='create'"
  162. ref="createb"
  163. type="success"
  164. @click="add_dialog_save_again()"
  165. >
  166. 确认新增
  167. </el-button>
  168. <el-button type="primary" @click="dialogStatus==='create'?add_dialog_save():edit_dialog_save()">
  169. 确认
  170. </el-button>
  171. <el-button @click="dialogFormVisible = false">
  172. 关闭
  173. </el-button>
  174. </div>
  175. </el-dialog>
  176. </div>
  177. </div>
  178. </template>
  179. <script>
  180. import TreeSelect from '@/components/TreeSelect'
  181. import waves from '@/directive/waves' // waves directive
  182. import { isIntegerZero } from '@/utils/validate'
  183. import { PostDataByName, GetDataByName, transData } from '@/api/common'
  184. import { MessageBox } from 'element-ui'
  185. import { sortChange } from '@/utils/index.js'
  186. export default {
  187. name: 'Menu',
  188. components: { TreeSelect },
  189. directives: { waves },
  190. filters: {
  191. menutypeFilter(menutype) {
  192. const menutypeMap = {
  193. menu: '',
  194. button: 'warning'
  195. }
  196. return menutypeMap[menutype]
  197. }
  198. },
  199. data() {
  200. return {
  201. disabled: false,
  202. tableKey: 0,
  203. list: [{ 'deptname': '公司', 'id': 1, 'parentid': -1, 'remark': '' }],
  204. parent: [],
  205. parentmenu: [],
  206. parentButton: [],
  207. listLoading: true,
  208. requestParam: {
  209. name: 'createdept',
  210. params: []
  211. },
  212. deptform: {
  213. id: '',
  214. name: '',
  215. title: '',
  216. path: '',
  217. component: '',
  218. icon: '',
  219. redirect: '',
  220. sort: '',
  221. parnetid: '',
  222. menutype: '',
  223. enable: ''
  224. },
  225. get_table_dataParm: { name: 'getMenuAndButtonRecu' },
  226. getRecuListParm: { name: 'getMenuListRecu' },
  227. getRecuListBParm: { name: 'getMenuListBRecu',
  228. idname: 'id',
  229. parammaps: { id: -2 }
  230. },
  231. rules: {
  232. name: [{ type: 'string', required: true, message: '菜单名称必填', trigger: 'change' }],
  233. title: [{ type: 'string', required: true, message: '菜单标题必填', trigger: 'change' }],
  234. path: [{ type: 'string', required: true, message: '路径必填', trigger: 'change' }],
  235. component: [{ type: 'string', required: true, message: '组件必填', trigger: 'change' }],
  236. sort: [{ validator: isIntegerZero, trigger: 'blur' }]
  237. },
  238. dialogFormVisible: false,
  239. dialogStatus: '',
  240. textMap: {
  241. update: '编辑',
  242. create: '新增'
  243. },
  244. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  245. cellStyle: { padding: 0 + 'px' },
  246. defaultProps: {
  247. children: 'children',
  248. label: 'title'
  249. },
  250. nodeKey: 'id',
  251. defaultCheckedKeys: []
  252. }
  253. },
  254. created() {
  255. this.get_table_data()
  256. },
  257. methods: {
  258. tableSort(column) {
  259. sortChange(column, this.list)
  260. },
  261. popoverHide(checkedIds, checkedData) {
  262. this.deptform.parentid = checkedIds
  263. },
  264. menutypechange() {
  265. if (this.deptform.menutype === 'menu') {
  266. this.parent = this.parentmenu
  267. } else { this.parent = this.parentButton }
  268. },
  269. get_table_data() {
  270. this.listLoading = true
  271. GetDataByName(this.get_table_dataParm).then(response => {
  272. if (response.data.list !== null) {
  273. for (var i = 0; i < response.data.list.length; i++) {
  274. response.data.list[i].enable = parseInt(response.data.list[i].enable)
  275. if (response.data.list[i].name == '首页') {
  276. response.data.list.splice(i, 1)
  277. }
  278. }
  279. this.list = transData(response.data.list, 'id', 'parentid', 'children')
  280. console.log(this.list, '-----------------')
  281. }
  282. this.get_select_list()
  283. // Just to simulate the time of the request
  284. setTimeout(() => {
  285. this.listLoading = false
  286. }, 0.5 * 1000)
  287. })
  288. },
  289. get_select_list() {
  290. GetDataByName(this.getRecuListParm).then(response => {
  291. if (response.data.list !== null) {
  292. this.parentmenu = transData(response.data.list, 'id', 'parentid', 'children')
  293. }
  294. })
  295. },
  296. refreshDownList() {
  297. for (var val of this.parentmenu) {
  298. this.parent = []
  299. if (val.redirect === 'noredirect' && this.deptform.menutype === 'menu') {
  300. this.parent.push({ id: val.id, title: val.title, parentid: val.parentid })
  301. } else if (this.deptform.menutype === 'button') {
  302. this.parent.push({ id: val.id, title: val.title, parentid: val.parentid })
  303. }
  304. }
  305. },
  306. resetRequestParam() {
  307. this.deptform.id = ''
  308. this.deptform.parentid = '-1'
  309. this.deptform.name = ''
  310. this.deptform.title = ''
  311. this.deptform.path = ''
  312. this.deptform.component = 'Layout'
  313. this.deptform.icon = ''
  314. this.deptform.redirect = ''
  315. this.deptform.sort = '0'
  316. this.deptform.menutype = ''
  317. this.deptform.enable = '1'
  318. },
  319. form_add() {
  320. this.resetRequestParam()
  321. this.dialogStatus = 'create'
  322. this.parent = this.parentmenu
  323. this.dialogFormVisible = true
  324. this.$nextTick(() => {
  325. this.$refs['dataForm'].clearValidate()
  326. this.$refs.name.focus()
  327. })
  328. },
  329. add_dialog_save() {
  330. this.$refs['dataForm'].validate((valid) => {
  331. if (valid) {
  332. this.requestParam.name = 'createMenu'
  333. this.requestParam.params = []
  334. if (this.deptform.parentid === '') this.deptform.parentid = '-1'
  335. this.requestParam.params[0] = this.deptform.parentid
  336. this.requestParam.params[1] = this.deptform.name
  337. this.requestParam.params[2] = this.deptform.title
  338. this.requestParam.params[3] = this.deptform.path
  339. this.requestParam.params[4] = this.deptform.component
  340. this.requestParam.params[5] = this.deptform.icon
  341. this.requestParam.params[6] = this.deptform.redirect
  342. this.requestParam.params[7] = this.deptform.sort
  343. this.requestParam.params[8] = this.deptform.menutype
  344. this.requestParam.params[9] = this.deptform.enable
  345. PostDataByName(this.requestParam).then(() => {
  346. this.get_table_data()
  347. this.dialogFormVisible = false
  348. this.$notify({
  349. title: '成功',
  350. message: '新增成功',
  351. type: 'success',
  352. duration: 2000
  353. })
  354. })
  355. }
  356. })
  357. },
  358. add_dialog_save_again() {
  359. this.$refs['dataForm'].validate((valid) => {
  360. if (valid) {
  361. this.requestParam.name = 'createMenu'
  362. this.requestParam.params = []
  363. this.requestParam.params[0] = this.deptform.parentid
  364. this.requestParam.params[1] = this.deptform.name
  365. this.requestParam.params[2] = this.deptform.title
  366. this.requestParam.params[3] = this.deptform.path
  367. this.requestParam.params[4] = this.deptform.component
  368. this.requestParam.params[5] = this.deptform.icon
  369. this.requestParam.params[6] = this.deptform.redirect
  370. this.requestParam.params[7] = this.deptform.sort
  371. this.requestParam.params[8] = this.deptform.menutype
  372. this.requestParam.params[9] = this.deptform.enable
  373. PostDataByName(this.requestParam).then(() => {
  374. this.$nextTick(() => {
  375. this.$refs['name'].focus()
  376. })
  377. this.get_table_data()
  378. this.requestParam = {
  379. name: 'createMenu',
  380. params: []
  381. }
  382. this.resetRequestParam()
  383. this.$notify({
  384. title: '成功',
  385. message: '新增成功',
  386. type: 'success',
  387. duration: 2000
  388. })
  389. })
  390. }
  391. })
  392. },
  393. form_edit(row) {
  394. this.defaultCheckedKeys = [row.parentid]
  395. this.deptform.parentid = row.parentid
  396. this.deptform.name = row.name
  397. this.deptform.title = row.title
  398. this.deptform.path = row.path
  399. this.deptform.component = row.component
  400. this.deptform.icon = row.icon
  401. this.deptform.redirect = row.redirect
  402. this.deptform.sort = row.sort
  403. this.deptform.id = row.id
  404. this.deptform.menutype = row.menutype
  405. this.deptform.enable = row.enable
  406. this.dialogStatus = 'update'
  407. this.menutypechange()
  408. this.dialogFormVisible = true
  409. this.$nextTick(() => {
  410. this.$refs['dataForm'].clearValidate()
  411. this.$refs['name'].focus()
  412. })
  413. },
  414. edit_dialog_save() {
  415. this.$refs['dataForm'].validate((valid) => {
  416. if (valid) {
  417. this.requestParam.name = 'updateMenu'
  418. this.requestParam.params = []
  419. this.requestParam.params[0] = this.deptform.parentid
  420. this.requestParam.params[1] = this.deptform.name
  421. this.requestParam.params[2] = this.deptform.title
  422. this.requestParam.params[3] = this.deptform.path
  423. this.requestParam.params[4] = this.deptform.component
  424. this.requestParam.params[5] = this.deptform.icon
  425. this.requestParam.params[6] = this.deptform.redirect
  426. this.requestParam.params[7] = this.deptform.sort
  427. this.requestParam.params[8] = this.deptform.menutype
  428. this.requestParam.params[9] = this.deptform.enable
  429. this.requestParam.params[10] = this.deptform.id
  430. console.log(this.requestParam)
  431. PostDataByName(this.requestParam).then(() => {
  432. this.get_table_data()
  433. this.dialogFormVisible = false
  434. this.$notify({
  435. title: '成功',
  436. message: '修改成功',
  437. type: 'success',
  438. duration: 2000
  439. })
  440. })
  441. }
  442. })
  443. },
  444. handleEnableChange(index, row) {
  445. this.requestParam.name = 'updateMenu'
  446. this.requestParam.params = []
  447. this.requestParam.params[0] = row.parentid
  448. this.requestParam.params[1] = row.name
  449. this.requestParam.params[2] = row.title
  450. this.requestParam.params[3] = row.path
  451. this.requestParam.params[4] = row.component
  452. this.requestParam.params[5] = row.icon
  453. this.requestParam.params[6] = row.redirect
  454. this.requestParam.params[7] = row.sort
  455. this.requestParam.params[8] = row.menutype
  456. this.requestParam.params[9] = row.enable
  457. this.requestParam.params[10] = row.id
  458. PostDataByName(this.requestParam).then(() => {
  459. this.$notify({
  460. title: '成功',
  461. message: '修改成功',
  462. type: 'success',
  463. duration: 2000
  464. })
  465. })
  466. },
  467. form_delete(row) {
  468. MessageBox.confirm('菜单名称:' + row.name, '确认删除?', {
  469. confirmButtonText: '确认',
  470. cancelButtonText: '取消',
  471. type: 'warning'
  472. }).then(() => {
  473. this.requestParam.name = 'deleteMenu'
  474. this.requestParam.params = []
  475. this.requestParam.params[0] = row.id
  476. PostDataByName(this.requestParam).then(() => {
  477. this.get_table_data()
  478. this.dialogFormVisible = false
  479. this.$notify({
  480. title: '成功',
  481. message: '删除成功',
  482. type: 'success',
  483. duration: 2000
  484. })
  485. })
  486. })
  487. }
  488. }
  489. }
  490. </script>