addEditor.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <div class="w-full h-full flex flex-col">
  3. <div class="flex-1 overflow-y-auto">
  4. <CustomerForm ref="formFormRef" :formJson="formJson" :formValue="formVal"></CustomerForm>
  5. </div>
  6. <div class="mar-20px ">
  7. <van-button type="primary" @click="onSubmit" class="w-full">
  8. {{ Object.keys(formVal).length > 0 ? '确定修改' : '确定添加' }}
  9. </van-button>
  10. </div>
  11. </div>
  12. </template>
  13. <script setup>
  14. import { ref, onActivated } from 'vue';
  15. import { useLifecycle } from '@hooks/useCommon.js';
  16. import CustomerForm from '@components/common/formForm/formView.vue'
  17. import requests from "@common/requests";
  18. import useToast from "@hooks/useToast"
  19. import { CUSTOMER_ADDED_EDITOR } from "@hooks/useApi"
  20. import { routingInfos, getRouterImg } from "@utility/generalVariables.js";
  21. import useRouterStore from "@store/useRouterStore.js";
  22. import commonUtil from "@utility/commonUtil"
  23. const router = useRouterStore()
  24. const { toastText, toastSuccess, toastFail, toastLoading } = useToast()
  25. const props = defineProps({
  26. formJson: { required: true },
  27. formValue: { required: true },
  28. });
  29. const formFormRef = ref(null)
  30. const formVal = ref({})
  31. function onSubmit() {
  32. formFormRef.value.getJsonData().then((res) => {
  33. if(!res.data) {
  34. return
  35. }
  36. toastLoading('保存中', 0)
  37. requests.post(CUSTOMER_ADDED_EDITOR, { ...commonUtil.getFromValue({ ...props.formValue, ...res.data }) }).then(() => {
  38. toastSuccess('保存成功')
  39. const currentPages = router.$state.currentPages || []
  40. const parentRoute = (currentPages[currentPages.length - 2] || {}).pathName
  41. const jumpTo = routingInfos['customer']
  42. setTimeout(() => {
  43. if(parentRoute == 'home') {
  44. router.redirectTo({
  45. pathName: 'moduleList',
  46. success: () => {
  47. router.eventEmit('moduleListRefreshData', {})
  48. router.emit('moduleListDetailParameter', {
  49. row: JSON.stringify(jumpTo)
  50. })
  51. }
  52. })
  53. } else {
  54. router.navigateBack({
  55. success: () => {
  56. router.eventEmit('moduleListRefreshData', {})
  57. }
  58. })
  59. }
  60. }, 2000)
  61. // setTimeout(() => {
  62. // router.navigateBack({
  63. // success: () => {
  64. // router.eventEmit('moduleListRefreshData', {})
  65. // }
  66. // })
  67. // }, 2000)
  68. }).catch(() => {
  69. toastFail('保存失败')
  70. })
  71. })
  72. }
  73. useLifecycle({
  74. load: () => {
  75. formVal.value = props.formValue
  76. },
  77. init: () => {
  78. formVal.value = props.formValue
  79. }
  80. });
  81. onActivated(() => {
  82. })
  83. </script>
  84. <style lang='scss' scoped>
  85. /* 样式代码 */
  86. </style>