731f47e9ac68d038737cfbe17414de0d39f0e836.svn-base 17 KB

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