index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <div class="sy-content">
  3. <el-row>
  4. <el-col :span="24">
  5. <!-- 表单查询 -->
  6. <el-form
  7. ref="queryForm"
  8. :model="queryParams"
  9. :inline="true"
  10. size="small"
  11. >
  12. <el-form-item
  13. label="菜单名称"
  14. prop="menuName"
  15. >
  16. <el-input
  17. v-model="queryParams.menuName"
  18. placeholder="请输入菜单名称"
  19. clear
  20. />
  21. </el-form-item>
  22. <el-form-item>
  23. <el-button
  24. type="primary"
  25. icon="el-icon-search"
  26. size="mini"
  27. @click="handelSearch"
  28. >搜索</el-button>
  29. <el-button
  30. icon="el-icon-refresh"
  31. size="mini"
  32. @click="handelReset"
  33. >重置</el-button>
  34. </el-form-item>
  35. </el-form>
  36. <el-button
  37. size="mini"
  38. icon="el-icon-plus"
  39. type="primary"
  40. plain
  41. @click="handelAdd"
  42. >新增</el-button>
  43. <!-- 表格数据信息 -->
  44. <el-table
  45. v-loading="loading"
  46. :data="menuList"
  47. row-key="id"
  48. >
  49. <el-table-column
  50. type="index"
  51. width="50"
  52. align="center"
  53. />
  54. <el-table-column
  55. key="menuName"
  56. label="菜单名称"
  57. align="center"
  58. prop="menuName"
  59. />
  60. <el-table-column
  61. key="menuIcon"
  62. label="菜单图标"
  63. align="center"
  64. prop="menuIcon"
  65. />
  66. <el-table-column
  67. key="menuUrl"
  68. label="路由地址"
  69. align="center"
  70. prop="menuUrl"
  71. />
  72. <el-table-column
  73. key="sortNum"
  74. label="排序号"
  75. align="center"
  76. prop="sortNum"
  77. />
  78. <el-table-column
  79. key="createTime"
  80. label="创建时间"
  81. align="center"
  82. prop="createTime"
  83. width="160"
  84. />
  85. <el-table-column
  86. key="updateTime"
  87. label="更新时间"
  88. align="center"
  89. prop="updateTime"
  90. width="160"
  91. >
  92. <template slot-scope="scope">
  93. {{ scope.row.updateTime === null ? scope.row.createTime : scope.row.updateTime }}
  94. </template>
  95. </el-table-column>
  96. <el-table-column
  97. label="操作"
  98. align="center"
  99. width="250"
  100. class-name="small-padding fixed-width"
  101. >
  102. <template slot-scope="scope">
  103. <el-button
  104. size="mini"
  105. type="text"
  106. icon="el-icon-edit"
  107. @click="handelEdit(scope.row.id)"
  108. >修改
  109. </el-button>
  110. <el-button
  111. size="mini"
  112. type="text"
  113. icon="el-icon-delete"
  114. @click="handelDel(scope.row.id)"
  115. >删除
  116. </el-button>
  117. <el-button
  118. size="mini"
  119. type="text"
  120. icon="el-icon-zoom-in"
  121. @click="handelAuth(scope.row.id)"
  122. >分配接口
  123. </el-button>
  124. </template>
  125. </el-table-column>
  126. </el-table>
  127. <!-- 分页信息 -->
  128. <pagination
  129. v-show="total > 0"
  130. :total="total"
  131. :page.sync="queryParams.page"
  132. :limit.sync="queryParams.limit"
  133. align="right"
  134. @pagination="getMenuList"
  135. />
  136. </el-col>
  137. </el-row>
  138. <!-- 弹出框 -->
  139. <el-dialog
  140. :title="title"
  141. :visible.sync="dialogVisible"
  142. width="800px"
  143. >
  144. <el-form
  145. ref="form"
  146. :model="form"
  147. :rules="rules"
  148. label-width="80px"
  149. >
  150. <el-row>
  151. <el-col :span="24">
  152. <el-form-item
  153. label="上级菜单"
  154. prop="parentId"
  155. >
  156. <selectTree
  157. v-model="form.parentId"
  158. :options="options"
  159. placeholder="请选择菜单"
  160. key-name="menuName"
  161. />
  162. </el-form-item>
  163. </el-col>
  164. </el-row>
  165. <el-row>
  166. <el-col :span="24">
  167. <el-form-item
  168. label="菜单图标"
  169. prop="menuIcon"
  170. >
  171. <el-input
  172. v-model="form.menuIcon"
  173. placeholder="请输入图标名称"
  174. />
  175. </el-form-item>
  176. </el-col>
  177. </el-row>
  178. <el-row>
  179. <el-col :span="12">
  180. <el-form-item
  181. label="菜单名称"
  182. prop="menuName"
  183. >
  184. <el-input
  185. v-model="form.menuName"
  186. placeholder="请输入菜单名称"
  187. />
  188. </el-form-item>
  189. </el-col>
  190. <el-col :span="12">
  191. <el-form-item
  192. label="显示排序"
  193. prop="sortNum"
  194. >
  195. <el-input-number
  196. v-model="form.sortNum"
  197. placeholder="0"
  198. controls-position="right"
  199. :min="1"
  200. :max="10"
  201. />
  202. </el-form-item>
  203. </el-col>
  204. </el-row>
  205. <el-row>
  206. <el-col :span="24">
  207. <el-form-item
  208. label="路由地址"
  209. prop="menuUrl"
  210. >
  211. <el-input
  212. v-model="form.menuUrl"
  213. placeholder="请输入路由地址"
  214. />
  215. </el-form-item>
  216. </el-col>
  217. </el-row>
  218. </el-form>
  219. <span
  220. slot="footer"
  221. class="dialog-footer"
  222. >
  223. <el-button
  224. type="primary"
  225. @click="handelSubmit('form')"
  226. >确 定</el-button>
  227. <el-button @click="handelCancel('form')">取 消</el-button>
  228. </span>
  229. </el-dialog>
  230. </div>
  231. </template>
  232. <script>
  233. import { getMenuList, addtMenuList, detailtMenuList, delMenuList, editMenuList } from '@/api/system/menu.js'
  234. import selectTree from '@/components/SelectTree'
  235. export default {
  236. components: {
  237. selectTree
  238. },
  239. data() {
  240. return {
  241. // 遮罩层
  242. loading: true,
  243. // 查询参数
  244. queryParams: {
  245. page: 1,
  246. limit: 10
  247. },
  248. // 总条数
  249. total: 0,
  250. // 表格数据
  251. menuList: [],
  252. // 弹出框
  253. dialogVisible: false,
  254. // 弹出框标题
  255. title: '',
  256. // 弹出框表单
  257. form: {},
  258. // 菜单类别
  259. options: [],
  260. // 表单验证
  261. rules: {
  262. menuName: [
  263. { required: true, message: '菜单名称不能为空', trigger: 'blur' }
  264. ],
  265. sortNum: [
  266. { required: true, message: '显示排序不能为空', trigger: ['change', 'blur'] }
  267. ],
  268. menuUrl: [
  269. { required: true, message: '路由地址不能为空', trigger: 'blur' }
  270. ]
  271. },
  272. // 修改菜单id
  273. id: null
  274. }
  275. },
  276. created() {
  277. this.getMenuList()
  278. },
  279. methods: {
  280. /** 获取表格数据 */
  281. getMenuList() {
  282. getMenuList(this.queryParams).then(response => {
  283. const data = response.data
  284. this.menuList = this.$utils.toArrayTree(data.menuList)
  285. this.total = data.count
  286. this.loading = false
  287. this.getOptionsList()
  288. })
  289. },
  290. /** 获取上级菜单 */
  291. getOptionsList() {
  292. getMenuList({
  293. page: 1,
  294. limit: 999
  295. }).then(res => {
  296. if (res.code === 200) {
  297. const data = res.data
  298. this.options = this.$utils.toArrayTree(data.menuList)
  299. }
  300. })
  301. },
  302. /** 搜索 */
  303. handelSearch() {
  304. this.queryParams.page = 1
  305. this.getMenuList()
  306. },
  307. /** 重置按钮操作 */
  308. handelReset() {
  309. this.$refs['queryForm'].resetFields()
  310. this.handelSearch()
  311. },
  312. /** 新增按钮 */
  313. handelAdd() {
  314. this.reset()
  315. this.dialogVisible = true
  316. this.title = '添加菜单'
  317. },
  318. /** 修改按钮 */
  319. handelEdit(id) {
  320. this.id = id
  321. detailtMenuList({ id }).then(res => {
  322. this.form = res.data
  323. })
  324. this.dialogVisible = true
  325. this.title = '修改菜单'
  326. },
  327. /** 删除按钮 */
  328. handelDel(id) {
  329. this.$confirm('是否删除该菜单?', '提示', {
  330. confirmButtonText: '确定',
  331. cancelButtonText: '取消',
  332. cancelButtonClass: 'btn_custom_cancel',
  333. type: 'warning'
  334. }).then(() => {
  335. delMenuList({ id }).then(res => {
  336. if (res.code === 200) {
  337. this.$message({
  338. type: 'success',
  339. message: res.data
  340. })
  341. this.getMenuList()
  342. }
  343. })
  344. }).catch(() => {
  345. this.$message({
  346. type: 'info',
  347. message: '已取消删除'
  348. })
  349. })
  350. },
  351. /** 表单提交 */
  352. handelSubmit(formName) {
  353. this.$refs[formName].validate((valid) => {
  354. if (valid) {
  355. if (this.title === '添加菜单') {
  356. this.form.parentId = this.form.parentId || 0
  357. addtMenuList(this.form).then(res => {
  358. if (res.code === 200) {
  359. this.$message({
  360. message: res.data,
  361. type: 'success'
  362. })
  363. this.getMenuList()
  364. this.dialogVisible = false
  365. }
  366. })
  367. } else {
  368. this.form.id = this.id
  369. editMenuList(this.form).then(res => {
  370. if (res.code === 200) {
  371. this.$message({
  372. message: res.data,
  373. type: 'success'
  374. })
  375. this.getMenuList()
  376. this.dialogVisible = false
  377. }
  378. })
  379. }
  380. }
  381. })
  382. },
  383. /** 表单取消 */
  384. handelCancel() {
  385. this.dialogVisible = false
  386. this.reset()
  387. },
  388. /** 表单重置 */
  389. reset() {
  390. if (this.$refs['form']) {
  391. this.$refs['form'].resetFields()
  392. }
  393. },
  394. /** 分配接口按钮 */
  395. handelAuth(id) {
  396. this.$router.push('/system/menu/menu-auth/auth/' + id)
  397. }
  398. }
  399. }
  400. </script>
  401. <style lang="scss" rel="stylesheet/scss" scoped>
  402. </style>