view-form.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <div>
  3. <el-dialog
  4. v-model="state.showDialog"
  5. destroy-on-close
  6. :title="title"
  7. draggable
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. width="600px"
  11. >
  12. <el-form :model="form" ref="formRef" size="default" label-width="80px">
  13. <el-row :gutter="35">
  14. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  15. <el-form-item label="应用" prop="label">
  16. <el-input v-model="state.app" clearable disabled />
  17. </el-form-item>
  18. </el-col>
  19. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  20. <el-form-item label="上级视图">
  21. <el-tree-select
  22. v-model="form.parentId"
  23. :data="viewTreeData"
  24. node-key="id"
  25. check-strictly
  26. default-expand-all
  27. render-after-expand
  28. fit-input-width
  29. clearable
  30. class="w100"
  31. />
  32. </el-form-item>
  33. </el-col>
  34. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  35. <el-form-item label="视图名称" prop="label" :rules="[{ required: true, message: '请输入视图名称', trigger: ['blur', 'change'] }]">
  36. <el-input v-model="form.label" clearable />
  37. </el-form-item>
  38. </el-col>
  39. <!-- <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  40. <el-form-item label="视图命名" prop="path">
  41. <el-input v-model="form.name" clearable />
  42. </el-form-item>
  43. </el-col> -->
  44. <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  45. <el-form-item label="视图地址" prop="path">
  46. <el-input v-model="form.path" clearable />
  47. </el-form-item>
  48. </el-col>
  49. <el-col :xs="24" :sm="10" :md="10" :lg="10" :xl="10">
  50. <el-form-item label="排序">
  51. <el-input-number v-model="form.sort" />
  52. </el-form-item>
  53. </el-col>
  54. <!-- <el-col :xs="24" :sm="7" :md="7" :lg="7" :xl="7">
  55. <el-form-item label="缓存">
  56. <el-switch v-model="form.cache" />
  57. </el-form-item>
  58. </el-col>
  59. <el-col :xs="24" :sm="7" :md="7" :lg="7" :xl="7">
  60. <el-form-item label="启用">
  61. <el-switch v-model="form.enabled" />
  62. </el-form-item>
  63. </el-col> -->
  64. <!-- <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
  65. <el-form-item label="视图描述" prop="description">
  66. <el-input v-model="form.description" clearable type="textarea" />
  67. </el-form-item>
  68. </el-col> -->
  69. </el-row>
  70. </el-form>
  71. <template #footer>
  72. <span class="dialog-footer">
  73. <el-button @click="onCancel" size="default">取 消</el-button>
  74. <el-button type="primary" @click="onSure" size="default" :loading="state.sureLoading">确 定</el-button>
  75. </span>
  76. </template>
  77. </el-dialog>
  78. </div>
  79. </template>
  80. <script lang="ts" setup name="admin/view/form">
  81. import { reactive, toRefs, ref, PropType } from 'vue'
  82. import { OauthView,OauthViewDto } from '/@/api/admin/data-contracts'
  83. import { ViewApi } from '/@/api/admin/View'
  84. import { PermissionApi } from '/@/api/admin/Permission'
  85. import eventBus from '/@/utils/mitt'
  86. defineProps({
  87. title: {
  88. type: String,
  89. default: '',
  90. },
  91. viewTreeData: {
  92. type: Array as PropType<OauthView[]>,
  93. default: () => [],
  94. },
  95. })
  96. const formRef = ref()
  97. const state = reactive({
  98. showDialog: false,
  99. sureLoading: false,
  100. form: {} as OauthViewDto,
  101. app:''
  102. })
  103. const { form } = toRefs(state)
  104. // 打开对话框
  105. const open = async (app:any,row: any = {}) => {
  106. // if (row.id > 0) {
  107. // const res = await new PermissionApi().getViewInfo({ id: row.id }, { loading: true })
  108. // if (res?.success) {
  109. // let formData = res.data as OauthViewDto
  110. // state.form = formData
  111. // }
  112. // } else {
  113. // state.form = {} as OauthViewDto
  114. // }
  115. state.app=app
  116. state.form=row
  117. state.showDialog = true
  118. }
  119. // 取消
  120. const onCancel = () => {
  121. state.showDialog = false
  122. }
  123. // 确定
  124. const onSure = () => {
  125. formRef.value.validate(async (valid: boolean) => {
  126. if (!valid) return
  127. state.sureLoading = true
  128. let res = {} as any
  129. const appData=await new PermissionApi().getApplyInfo({name:state.app})
  130. state.form.appID=appData.data[0].id
  131. if (state.form.id != undefined && state.form.id > 0) {
  132. res = await new PermissionApi().addView(state.form, { showSuccessMessage: true }).catch(() => {
  133. state.sureLoading = false
  134. })
  135. } else {
  136. res = await new PermissionApi().addView(state.form, { showSuccessMessage: true }).catch(() => {
  137. state.sureLoading = false
  138. })
  139. }
  140. state.sureLoading = false
  141. if (res?.success) {
  142. eventBus.emit('refreshView')
  143. state.showDialog = false
  144. }
  145. })
  146. }
  147. defineExpose({
  148. open,
  149. })
  150. </script>