auth.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div class="app-list-content">
  3. <cl-crud @load="onLoad">
  4. <template #table-column-icon="{scope}">
  5. <icon-svg :name="scope.row.icon" size="20px"></icon-svg>
  6. </template>
  7. <!-- <template #table-column-perms="{scope}">
  8. <el-tag
  9. size="medium"
  10. v-for="(item, index) in scope.row.permList"
  11. :key="index"
  12. style="margin: 2px"
  13. >{{ item }}</el-tag
  14. >
  15. </template> -->
  16. <!--
  17. <template #table-column-router="{scope}">
  18. <el-link type="primary" :href="scope.row.router" v-if="scope.row.type == 1">{{
  19. scope.row.router
  20. }}</el-link>
  21. <span v-else>{{ scope.row.router }}</span>
  22. </template>
  23. <template #table-column-keepAlive="{scope}">
  24. <template v-if="scope.row.type == 1">
  25. <i class="el-icon-check" v-if="scope.row.keepAlive"></i>
  26. <i class="el-icon-close" v-else></i>
  27. </template>
  28. </template> -->
  29. <template #slot-column-op="{scope}">
  30. <el-button
  31. type="text"
  32. size="mini"
  33. @click="upsertAppend(scope.row)"
  34. v-if="scope.row.type != 2"
  35. >新增</el-button
  36. >
  37. </template>
  38. </cl-crud>
  39. <cl-context-menu ref="context-menu"></cl-context-menu>
  40. </div>
  41. </template>
  42. <script>
  43. import { deepTree } from '@/cool/utils/index';
  44. export default {
  45. data() {
  46. return {
  47. crud: null,
  48. parentArr: []
  49. };
  50. },
  51. methods: {
  52. onLoad({ ctx, app }) {
  53. this.crud = app;
  54. ctx.service(this.$service.sassAuth)
  55. .set('dict', {
  56. api: {
  57. page: 'authList',
  58. add: 'authAdd',
  59. update: 'authUpdate',
  60. delete: 'authDel'
  61. }
  62. })
  63. .set('table', {
  64. columns: [
  65. {
  66. prop: 'authName',
  67. label: '名称',
  68. width: 200
  69. },
  70. {
  71. prop: 'parentId',
  72. label: '父级ID',
  73. align: 'center',
  74. 'min-width': 160
  75. },
  76. {
  77. prop: 'frontUrl',
  78. label: '前端路由',
  79. align: 'center',
  80. 'min-width': 160
  81. },
  82. {
  83. prop: 'backUrl',
  84. label: '后端路由',
  85. align: 'center',
  86. 'min-width': 160
  87. }
  88. // {
  89. // prop: 'addTime',
  90. // label: '时间',
  91. // align: 'center',
  92. // sortable: true,
  93. // width: 180
  94. // }
  95. ],
  96. props: {
  97. 'row-key': 'id'
  98. },
  99. on: {
  100. 'row-click': (row, column) => {
  101. if (column.property && row.children) {
  102. app.refs('table').toggleRowExpansion(row);
  103. }
  104. },
  105. 'row-contextmenu': (row, column, event) => {
  106. let list = [
  107. {
  108. label: '编辑',
  109. callback: (e, close) => {
  110. app.edit(row);
  111. close();
  112. }
  113. },
  114. {
  115. label: '删除',
  116. callback: (e, close) => {
  117. app.delete(row);
  118. close();
  119. }
  120. }
  121. ];
  122. // if (row.type != 2) {
  123. // list.unshift({
  124. // label: '新增',
  125. // callback: (e, close) => {
  126. // this.upsertAppend(row);
  127. // close();
  128. // }
  129. // });
  130. // }
  131. this.$refs['context-menu'].open(event, {
  132. list
  133. });
  134. event.preventDefault();
  135. }
  136. },
  137. op: {
  138. props: {
  139. width: '200'
  140. },
  141. layout: ['slot-column-op', 'edit', 'delete']
  142. }
  143. })
  144. .set('upsert', {
  145. props: {
  146. width: '600px'
  147. },
  148. items: [
  149. {
  150. prop: 'parentId',
  151. label: '父权限',
  152. span: 24,
  153. component: {
  154. name: 'el-select',
  155. attrs: {
  156. placeholder: '请选择'
  157. },
  158. options: this.parentArr
  159. }
  160. // rules: {
  161. // required: true,
  162. // message: '级别不能为空'
  163. // }
  164. },
  165. {
  166. prop: 'name',
  167. label: '权限名',
  168. span: 24,
  169. component: {
  170. name: 'el-input',
  171. attrs: {
  172. placeholder: '请输入名称'
  173. }
  174. },
  175. rules: {
  176. required: true,
  177. message: '名称不能为空'
  178. }
  179. },
  180. {
  181. prop: 'frontUrl',
  182. label: '前端路由',
  183. span: 24,
  184. component: {
  185. name: 'el-input',
  186. attrs: {
  187. placeholder: '请输入'
  188. }
  189. },
  190. rules: {
  191. required: true,
  192. message: '前端路由不能为空'
  193. }
  194. },
  195. {
  196. prop: 'backUrl',
  197. label: '后端路由',
  198. span: 24,
  199. component: {
  200. name: 'el-input',
  201. attrs: {
  202. placeholder: '请输入'
  203. }
  204. }
  205. },
  206. {
  207. prop: 'endId',
  208. label: 'endId',
  209. span: 24,
  210. value: '1',
  211. hidden: true,
  212. component: {
  213. name: 'el-input',
  214. attrs: {
  215. placeholder: '请输入'
  216. }
  217. }
  218. }
  219. ]
  220. })
  221. .set('layout', [['refresh-btn', 'add-btn'], ['data-table']])
  222. .on('refresh', async (params, { next, render }) => {
  223. let { list } = await next(params);
  224. list = JSON.parse(JSON.stringify(list));
  225. list = list.map(e => {
  226. e.label = e.authName;
  227. e.value = e.id;
  228. return e;
  229. });
  230. this.crud.setData('upsert.items[prop:parentId].component.options', list);
  231. console.log(this.parentArr);
  232. })
  233. .done();
  234. app.refresh();
  235. },
  236. upsertAppend({ type, id }) {
  237. this.crud.append({
  238. parentId: id,
  239. type: type + 1
  240. });
  241. },
  242. setPermission({ id }) {
  243. this.crud.append({
  244. parentId: id,
  245. type: 2
  246. });
  247. },
  248. toUrl(url) {
  249. this.$router.push(url);
  250. }
  251. }
  252. };
  253. </script>