role.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <script setup lang="ts">
  2. import FormSearch from "@/components/opts/form-search.vue";
  3. import TableButtons from "@/components/opts/btns2.vue";
  4. import { PureTable } from "@pureadmin/table";
  5. import { hasAuth } from "@/router/utils";
  6. import { enableConvert, enabledBooleanConvert } from "@/constants/convert";
  7. import { enableOptions } from "@/constants/constants";
  8. import * as roleApi from "@/api/sys/role";
  9. import RoleEdit from "./modules/role-edit.vue";
  10. import RolePermission from "./modules/role-permission.vue";
  11. import { reactive, onMounted, ref } from "vue";
  12. const roleEditRef = ref();
  13. const rolePermissionRef = ref();
  14. const pageData: any = reactive({
  15. permission: {
  16. query: [],
  17. add: ["role:save"],
  18. update: ["role:update"],
  19. delete: ["role:del"],
  20. permission: ["role:permission"]
  21. },
  22. /**
  23. * 是否显示搜索
  24. */
  25. searchState: true,
  26. /*搜索字段定义 */
  27. searchField: [
  28. {
  29. type: "input",
  30. label: "角色编码",
  31. prop: "roleCode",
  32. placeholder: "精准查询角色编码"
  33. },
  34. {
  35. type: "input",
  36. label: "角色名称",
  37. prop: "roleName",
  38. placeholder: "模糊查询角色名称"
  39. },
  40. {
  41. type: "select",
  42. label: "状态",
  43. prop: "enable",
  44. placeholder: "请选择",
  45. dataSourceKey: "enabledOptions",
  46. options: {
  47. keys: {
  48. label: "label",
  49. value: "value",
  50. prop: "value"
  51. },
  52. filterable: true
  53. }
  54. }
  55. ],
  56. dataSource: {
  57. enabledOptions: enableOptions
  58. },
  59. searchForm: {},
  60. /*按钮 */
  61. btnOpts: {
  62. left: [
  63. {
  64. key: "add",
  65. label: "新增",
  66. type: "primary",
  67. icon: "ep:plus",
  68. state: true,
  69. permission: ["role:save"]
  70. }
  71. // {
  72. // key: "update",
  73. // label: "修改",
  74. // type: "success",
  75. // icon: "ep:edit",
  76. // state: false,
  77. // permission: ["role:update"]
  78. // }
  79. ],
  80. right: [
  81. {
  82. key: "search",
  83. label: "查询",
  84. icon: "ep:search",
  85. state: true,
  86. options: {
  87. circle: true
  88. }
  89. },
  90. {
  91. key: "refresh",
  92. label: "刷新",
  93. icon: "ep:refresh",
  94. state: true,
  95. options: {
  96. circle: true
  97. }
  98. }
  99. ]
  100. },
  101. tableParams: {
  102. /**
  103. * table column
  104. */
  105. columns: [
  106. {
  107. label: "角色编码",
  108. prop: "roleCode"
  109. },
  110. {
  111. label: "角色名称",
  112. prop: "roleName"
  113. },
  114. {
  115. label: "类型",
  116. props: "isSystem",
  117. slot: "roleType"
  118. },
  119. {
  120. label: "状态",
  121. prop: "enable",
  122. slot: "roleEnable"
  123. },
  124. {
  125. label: "创建时间",
  126. prop: "createTime"
  127. },
  128. {
  129. label: "操作",
  130. fixed: "right",
  131. slot: "operation"
  132. }
  133. ],
  134. /**
  135. * table data
  136. */
  137. list: [],
  138. /*加载 */
  139. loading: false,
  140. /*数据 */
  141. tableData: [],
  142. currentData: {},
  143. pagination: {
  144. pageSize: 10,
  145. defaultPageSize: 10,
  146. currentPage: 1,
  147. background: true,
  148. total: 0
  149. }
  150. }
  151. });
  152. /**
  153. * 更新搜索表单
  154. * @param data .
  155. */
  156. const _updateSearchFormData = (data: any) => {
  157. pageData.searchForm = data;
  158. };
  159. /**
  160. * 点击搜索按钮
  161. */
  162. const _searchForm = (data: any) => {
  163. pageData.searchForm = data;
  164. _loadData();
  165. };
  166. /**
  167. * 重置
  168. */
  169. const _resetSearchForm = (data?: any) => {
  170. pageData.searchForm = data;
  171. };
  172. /**
  173. * 更新搜索表达的状态
  174. */
  175. const _updateSearchState = () => {
  176. pageData.searchState = !pageData.searchState;
  177. };
  178. const handleChangePageSize = (val: any) => {
  179. pageData.tableParams.pagination.pageSize = val;
  180. _loadData();
  181. };
  182. const handleChangeCurrentPage = (val: any) => {
  183. pageData.tableParams.pagination.currentPage = val;
  184. _loadData();
  185. };
  186. const getQueryParams = () => {
  187. const sqp = {};
  188. const param = Object.assign(sqp, pageData.searchForm);
  189. param.current = pageData.tableParams.pagination.currentPage;
  190. param.size = pageData.tableParams.pagination.pageSize;
  191. return param;
  192. };
  193. /**
  194. * 查询数据
  195. */
  196. const _loadData = () => {
  197. pageData.tableParams.loading = true;
  198. const query = getQueryParams();
  199. roleApi
  200. .roleQueryPage(query)
  201. .then((res: any) => {
  202. if (res.success) {
  203. pageData.tableParams.list = res.result.records;
  204. pageData.tableParams.pagination.total = Number(res.result.total);
  205. }
  206. })
  207. .finally(() => {
  208. pageData.tableParams.loading = false;
  209. });
  210. };
  211. const handleBtnClick = (val: String) => {
  212. switch (val) {
  213. case "add":
  214. _handlerAdd();
  215. break;
  216. case "update":
  217. break;
  218. case "search":
  219. _updateSearchState();
  220. break;
  221. case "refresh":
  222. _loadData();
  223. break;
  224. }
  225. };
  226. /**
  227. * 新增
  228. */
  229. const _handlerAdd = () => {
  230. roleEditRef.value!.open();
  231. };
  232. const handleEdit = (data: any) => {
  233. roleEditRef.value!.open(data, "修改角色");
  234. };
  235. const handleAuthorize = (row: any) => {
  236. rolePermissionRef.value!.open(row);
  237. };
  238. onMounted(() => {
  239. _loadData();
  240. });
  241. defineOptions({ name: "sysRole" });
  242. </script>
  243. <template>
  244. <el-card :shadow="'never'">
  245. <template #default>
  246. <form-search
  247. :show="pageData.searchState"
  248. :form-field="pageData.searchField"
  249. :data-source="pageData.dataSource"
  250. @search-form="_updateSearchFormData"
  251. @search="_searchForm"
  252. @reset="_resetSearchForm"
  253. :query-permission="pageData.permission.query"
  254. />
  255. <table-buttons
  256. :size="'small'"
  257. :left-btns="pageData.btnOpts.left"
  258. :right-btns="pageData.btnOpts.right"
  259. @click="handleBtnClick"
  260. />
  261. <pure-table
  262. :columns="pageData.tableParams.columns"
  263. :data="pageData.tableParams.list"
  264. :border="true"
  265. :stripe="true"
  266. :loading="pageData.tableParams.loading"
  267. :pagination="pageData.tableParams.pagination"
  268. :header-row-class-name="'table-header'"
  269. @page-current-change="handleChangeCurrentPage"
  270. @page-size-change="handleChangePageSize"
  271. >
  272. <template #roleType="{ row }">
  273. <el-tag
  274. effect="plain"
  275. :type="enabledBooleanConvert(row.isSystem) ? 'danger' : ''"
  276. >{{
  277. enabledBooleanConvert(row.isSystem) ? "内置" : "自定义"
  278. }}</el-tag
  279. >
  280. </template>
  281. <template #roleEnable="{ row }">
  282. <el-tag
  283. effect="plain"
  284. :type="row.enable === 1 ? 'success' : 'info'"
  285. >{{ enableConvert(row.enable) }}</el-tag
  286. >
  287. </template>
  288. <template #operation="{ row }">
  289. <el-link
  290. v-show="
  291. hasAuth(pageData.permission.permission) && row.isSystem != 1
  292. "
  293. type="primary"
  294. @click="handleAuthorize(row)"
  295. >授权</el-link
  296. >
  297. <el-divider
  298. v-show="
  299. hasAuth(pageData.permission.permission) && row.isSystem != 1
  300. "
  301. direction="vertical"
  302. />
  303. <el-link
  304. v-show="hasAuth(pageData.permission.update) && row.isSystem !== 1"
  305. type="primary"
  306. @click="handleEdit(row)"
  307. >编辑</el-link
  308. >
  309. <el-divider
  310. v-show="hasAuth(pageData.permission.delete) && row.isSystem !== 1"
  311. direction="vertical"
  312. />
  313. <el-link
  314. v-show="hasAuth(pageData.permission.delete) && row.isSystem !== 1"
  315. type="primary"
  316. >删除</el-link
  317. >
  318. </template>
  319. </pure-table>
  320. <role-edit ref="roleEditRef" @ok="_loadData" />
  321. <role-permission ref="rolePermissionRef" />
  322. </template>
  323. </el-card>
  324. </template>