9d7ce2866e265ce7978804b5dbfc107a696d6539.svn-base 17 KB

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