index.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <script setup lang="ts">
  2. import { ref } from "vue";
  3. import { usePageSearch, type PageHooks, type PageEvents } from "/@/hooks/page";
  4. import RoleModal from "./components/role-modal.vue";
  5. import contentConfig from "./config/content.config";
  6. import searchConfig from "./config/search.config";
  7. import { httpSetRole } from "/@/api/system/account";
  8. import { useAsync } from "/@/hooks/core/useAsync";
  9. import { ModalTypes } from "./types";
  10. const PageName = "accountRole";
  11. const roleModalRef = ref<InstanceType<typeof RoleModal> | null>(null);
  12. const instance = ref(null);
  13. const searchCallback = params => ({
  14. result: { ...(params ? params : {}), level: "2" },
  15. deleteProp: []
  16. });
  17. const hooks: PageHooks = {
  18. pageSearchHook: () => usePageSearch(searchCallback, undefined, searchConfig)
  19. };
  20. const { run } = useAsync({
  21. success: () => instance.value.onSearch()
  22. });
  23. const events: PageEvents = {
  24. content: {
  25. create: () => roleModalRef.value.onDisplay(undefined, ModalTypes.create),
  26. preview: data => roleModalRef.value.onDisplay(data, ModalTypes.preview),
  27. update: data => roleModalRef.value.onDisplay(data, ModalTypes.update)
  28. }
  29. };
  30. function handleSave(data: any, type: ModalTypes) {
  31. const { roleid, id } = data;
  32. const params = {
  33. status: "1",
  34. user_id: id,
  35. role_id: roleid
  36. };
  37. switch (type) {
  38. case ModalTypes.update:
  39. run(httpSetRole(params));
  40. break;
  41. }
  42. }
  43. </script>
  44. <template>
  45. <PageAuth :pageName="PageName">
  46. <PageContainer
  47. :hooks="hooks"
  48. :events="events"
  49. :contentConfig="contentConfig"
  50. :search-config="searchConfig"
  51. :get-content-ref="ref => (instance = ref)"
  52. />
  53. <RoleModal ref="roleModalRef" @finance-save="handleSave" />
  54. </PageAuth>
  55. </template>