menu.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <script setup lang="ts">
  2. import FormSearch from "@/components/opts/form-search.vue";
  3. import TableButtons from "@/components/opts/btns2.vue";
  4. import MenuEdit from "./modules/menu-edit.vue";
  5. import { reactive, onMounted, ref } from "vue";
  6. import * as permissionApi from "@/api/sys/permission";
  7. import { PureTable } from "@pureadmin/table";
  8. import { useRenderIcon } from "@/components/ReIcon/src/hooks";
  9. import { hasAuth } from "@/router/utils";
  10. import message from "@/utils/message";
  11. const menuEditRef = ref();
  12. const pageData: any = reactive({
  13. permission: {
  14. query: ["menu:query"],
  15. add: ["menu:save"],
  16. update: ["menu:update"],
  17. delete: ["menu:del"]
  18. },
  19. searchState: true,
  20. /*搜索字段定义 */
  21. searchField: [
  22. {
  23. type: "input",
  24. label: "菜单名称",
  25. prop: "title",
  26. placeholder: "请输入菜单名称"
  27. }
  28. ],
  29. searchForm: {},
  30. /*按钮 */
  31. btnOpts: {
  32. // add: {
  33. // show: true,
  34. // state: true,
  35. // permission: ["menu:save"]
  36. // },
  37. // update: {
  38. // show: true,
  39. // state: true,
  40. // permission: ["menu:update"]
  41. // }
  42. size: "small",
  43. left: [
  44. {
  45. key: "add",
  46. label: "新增",
  47. type: "primary",
  48. icon: "ep:plus",
  49. state: true,
  50. permission: ["menu:save"]
  51. }
  52. // {
  53. // key: "update",
  54. // label: "修改",
  55. // type: "success",
  56. // icon: "ep:edit",
  57. // state: false,
  58. // permission: ["menu:update"]
  59. // }
  60. ],
  61. right: [
  62. {
  63. key: "search",
  64. label: "查询",
  65. icon: "ep:search",
  66. state: true,
  67. options: {
  68. circle: true
  69. }
  70. },
  71. {
  72. key: "refresh",
  73. label: "刷新",
  74. icon: "ep:refresh",
  75. state: true,
  76. options: {
  77. circle: true
  78. }
  79. }
  80. ]
  81. },
  82. tableParams: {
  83. /*加载 */
  84. loading: false,
  85. /*数据 */
  86. list: [],
  87. columns: [
  88. {
  89. label: "菜单名称",
  90. prop: "title"
  91. },
  92. {
  93. label: "菜单图标",
  94. prop: "icon",
  95. slot: "iconScope"
  96. },
  97. {
  98. label: "权限标识",
  99. prop: "perms"
  100. },
  101. {
  102. label: "是否缓存",
  103. prop: "keepAlive",
  104. slot: "booleanScope"
  105. },
  106. {
  107. label: "是否可见",
  108. prop: "showLink",
  109. slot: "booleanScope"
  110. },
  111. {
  112. label: "菜单类型",
  113. prop: "menuTypeName"
  114. },
  115. {
  116. label: "状态",
  117. prop: "enable",
  118. slot: "enabledScope"
  119. },
  120. {
  121. label: "操作",
  122. fixed: "right",
  123. slot: "operation"
  124. }
  125. ],
  126. currentData: {},
  127. pagination: {
  128. pageSize: 10,
  129. defaultPageSize: 10,
  130. currentPage: 1,
  131. background: true,
  132. total: 0
  133. }
  134. }
  135. });
  136. /**
  137. * 更新搜索表单
  138. * @param data .
  139. */
  140. const _updateSearchFormData = (data: any) => {
  141. pageData.searchForm = data;
  142. };
  143. /**
  144. * 点击搜索按钮
  145. */
  146. const _searchForm = (data: any) => {
  147. pageData.searchForm = data;
  148. _loadData();
  149. };
  150. /**
  151. * 重置
  152. */
  153. const _resetSearchForm = (data?) => {
  154. pageData.searchForm = data;
  155. };
  156. /**
  157. * 更新搜索表达的状态
  158. */
  159. const _updateSearchState = () => {
  160. pageData.searchState = !pageData.searchState;
  161. };
  162. /**
  163. * 查询数据
  164. */
  165. const _loadData = () => {
  166. pageData.tableParams.loading = true;
  167. const query = getQueryParams();
  168. permissionApi
  169. .treeList(query)
  170. .then((res: any) => {
  171. if (res.success) {
  172. pageData.tableParams.list = res.result || [];
  173. } else {
  174. message.warning(res.message);
  175. }
  176. })
  177. .finally(() => {
  178. pageData.tableParams.loading = false;
  179. });
  180. };
  181. const getQueryParams = () => {
  182. const sqp = {};
  183. const param = Object.assign(sqp, pageData.searchForm);
  184. return param;
  185. };
  186. const handleBtnClick = (val: String) => {
  187. switch (val) {
  188. case "add":
  189. _handlerAdd();
  190. break;
  191. case "update":
  192. break;
  193. case "search":
  194. _updateSearchState();
  195. break;
  196. case "refresh":
  197. _loadData();
  198. break;
  199. }
  200. };
  201. /**
  202. * 更新
  203. * @param data .
  204. */
  205. const _editMenu = (data: any) => {
  206. pageData.tableParams.currentData = data;
  207. menuEditRef.value!.open("update", data, "修改菜单/权限");
  208. };
  209. /**
  210. * table列新增
  211. * @param data .
  212. */
  213. const _handleRowAdd = (data: any) => {
  214. pageData.tableParams.currentData = data;
  215. menuEditRef.value!.open("save", { parentId: data.id }, "修改菜单/权限");
  216. };
  217. const _handleRowDel = (data: any) => {
  218. batchDel([data.id]);
  219. };
  220. const batchDel = (ids: string[]) => {
  221. if (ids && ids.length > 0) {
  222. permissionApi.deletePermission(ids).then((res: any) => {
  223. if (res.success) {
  224. message.success("删除成功");
  225. _loadData();
  226. } else {
  227. message.warning(res.message);
  228. }
  229. });
  230. }
  231. };
  232. /**
  233. * 新增
  234. */
  235. const _handlerAdd = () => {
  236. menuEditRef.value!.open("save", {}, "新增菜单/权限");
  237. };
  238. onMounted(() => {
  239. _loadData();
  240. });
  241. defineOptions({ name: "sysMenu" });
  242. </script>
  243. <template>
  244. <el-card :shadow="'never'">
  245. <template #default>
  246. <!--form search-->
  247. <FormSearch
  248. :show="pageData.searchState"
  249. :size="'default'"
  250. :form-field="pageData.searchField"
  251. @search-form="_updateSearchFormData"
  252. @search="_searchForm"
  253. @reset="_resetSearchForm"
  254. :query-permission="pageData.permission.query"
  255. />
  256. <!--operator-->
  257. <!-- <TableOperation
  258. :size="'small'"
  259. :add="pageData.btnOpts.add"
  260. @click-search="_updateSearchState"
  261. @click-refresh="_loadData"
  262. @click-add="_handlerAdd"
  263. /> -->
  264. <table-buttons
  265. :size="pageData.btnOpts.size"
  266. :left-btns="pageData.btnOpts.left"
  267. :right-btns="pageData.btnOpts.right"
  268. @click="handleBtnClick"
  269. />
  270. <!--table-->
  271. <pure-table
  272. :loading="pageData.tableParams.loading"
  273. :columns="pageData.tableParams.columns"
  274. :data="pageData.tableParams.list"
  275. :border="true"
  276. :stripe="true"
  277. :header-row-class-name="'table-header'"
  278. row-key="id"
  279. >
  280. <template #booleanScope="scope">
  281. {{ scope.row.keepAlive ? "是" : "否" }}
  282. </template>
  283. <template #iconScope="scope">
  284. <component :is="useRenderIcon(scope.row.icon)" />
  285. </template>
  286. <template #enabledScope="scope">
  287. <el-tag v-if="scope.row.enable">启用</el-tag>
  288. <el-tag v-else type="info">禁用</el-tag>
  289. </template>
  290. <template #operation="scope">
  291. <el-link
  292. :disabled="!hasAuth(pageData.permission.update)"
  293. type="primary"
  294. @click="_editMenu(scope.row)"
  295. >编辑</el-link
  296. >
  297. <el-divider direction="vertical" />
  298. <el-link
  299. :disabled="!hasAuth(pageData.permission.add)"
  300. type="primary"
  301. @click="_handleRowAdd(scope.row)"
  302. >新增</el-link
  303. >
  304. <el-divider direction="vertical" />
  305. <el-link
  306. :disabled="!hasAuth(pageData.permission.delete)"
  307. type="primary"
  308. @click="_handleRowDel(scope.row)"
  309. >删除</el-link
  310. >
  311. </template>
  312. </pure-table>
  313. <menu-edit ref="menuEditRef" @ok="_loadData()" />
  314. </template>
  315. </el-card>
  316. </template>
  317. <style scoped lang="scss">
  318. // :deep(.el-table .el-table__header-wrapper th) {
  319. // word-break: break-word;
  320. // background-color: #f8f8f9;
  321. // color: #515a6e;
  322. // height: 40px;
  323. // font-size: 13px;
  324. // }
  325. </style>