detail.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <CzrDialog
  3. :show="show"
  4. :title="titleCpt"
  5. @onClose="$emit('update:show', false)"
  6. @onSubmit="onSubmit"
  7. width="62.5rem"
  8. height="auto"
  9. max-height="90%"
  10. :loading="state.loading"
  11. >
  12. <div class="bm-form">
  13. <CzrForm ref="ref_form" label-width="100px" :form-view="isViewCpt">
  14. <div class="__czr-title_1">基本信息</div>
  15. <CzrFormColumn
  16. required
  17. :span="12"
  18. label="模型类型"
  19. v-model:param="state.form.type"
  20. link="select"
  21. :options="DictionaryStore.modelTypes.list"
  22. @change="state.form.pluginClass = ''"
  23. />
  24. <template v-if="state.form.type">
  25. <CzrFormColumn
  26. required
  27. :span="12"
  28. label="模型供应商"
  29. v-model:param="state.form.pluginClass"
  30. link="select"
  31. :options="
  32. DictionaryStore.modelProvides.list.filter(
  33. (v) => v.type === state.form.type,
  34. )
  35. "
  36. @getObject="getModelProvide"
  37. />
  38. </template>
  39. <template v-if="state.form.pluginClass">
  40. <CzrFormColumn
  41. required
  42. :span="24"
  43. label="模型名称"
  44. v-model:param="state.form.name"
  45. />
  46. <CzrFormColumn
  47. :span="24"
  48. label="模型简介"
  49. v-model:param="state.form.description"
  50. type="textarea"
  51. :rows="4"
  52. />
  53. </template>
  54. <CzrFormColumn
  55. required
  56. :span="24"
  57. label="共享条件"
  58. v-model:param="state.form.openStrategy"
  59. link="radio"
  60. :options="DictionaryStore.shareConditions"
  61. />
  62. <template v-if="state.form.pluginClass">
  63. <template v-if="state.baseForms?.length > 0">
  64. <div class="__czr-title_1">基本参数配置</div>
  65. <template v-for="item in state.baseForms">
  66. <modelFormInit :config="item" :form="state.form.basicConfigs" />
  67. </template>
  68. </template>
  69. <template v-if="state.paramForms?.length > 0">
  70. <div class="__czr-title_1">模型参数配置</div>
  71. <template v-for="item in state.paramForms">
  72. <modelFormInit :config="item" :form="state.form.paramConfigs" />
  73. </template>
  74. </template>
  75. <template v-if="state.bizForms?.length > 0">
  76. <div class="__czr-title_1">业务参数配置</div>
  77. <template v-for="item in state.bizForms">
  78. <modelFormInit :config="item" :form="state.form.bizConfigs" />
  79. </template>
  80. </template>
  81. </template>
  82. </CzrForm>
  83. </div>
  84. </CzrDialog>
  85. </template>
  86. <script setup lang="ts">
  87. import {
  88. computed,
  89. getCurrentInstance,
  90. nextTick,
  91. reactive,
  92. ref,
  93. watch,
  94. } from 'vue'
  95. import { ElMessage, ElMessageBox } from 'element-plus'
  96. import { useAppStore, useDialogStore, useDictionaryStore } from '@/stores'
  97. import { useRouter } from 'vue-router'
  98. import modelFormInit from './model-form-init.vue'
  99. import {
  100. pluginAddInstance,
  101. pluginDetail,
  102. pluginUpdateInstance,
  103. } from '@/api/modules/model'
  104. const router = useRouter()
  105. const AppStore = useAppStore()
  106. const DictionaryStore = useDictionaryStore()
  107. const DialogStore = useDialogStore()
  108. const emit = defineEmits(['update:show', 'refresh'])
  109. const { proxy } = getCurrentInstance()
  110. const props = defineProps({
  111. show: { default: false },
  112. transfer: <any>{},
  113. })
  114. const state: any = reactive({
  115. loading: false,
  116. form: {
  117. basicConfigs: {},
  118. paramConfigs: {},
  119. bizConfigs: {},
  120. },
  121. baseForms: [],
  122. paramForms: [],
  123. bizForms: [],
  124. })
  125. const ref_form = ref()
  126. const titleCpt = computed(() => {
  127. let t = '模型'
  128. switch (props.transfer.mode) {
  129. case 'add':
  130. t = '创建' + t
  131. break
  132. case 'edit':
  133. t = '编辑' + t
  134. break
  135. case 'view':
  136. t = '查看' + t
  137. break
  138. }
  139. return t
  140. })
  141. const isViewCpt = computed(() => props.transfer?.mode === 'view')
  142. watch(
  143. () => props.show,
  144. (n) => {
  145. if (n) {
  146. initDictionary()
  147. state.form = {
  148. tenantId: AppStore.tenantInfo?.id,
  149. basicConfigs: {},
  150. paramConfigs: {},
  151. bizConfigs: {},
  152. }
  153. state.baseForms = []
  154. state.paramForms = []
  155. state.bizForms = []
  156. if (props.transfer.mode !== 'add') {
  157. initData()
  158. }
  159. nextTick(() => {
  160. ref_form.value.reset()
  161. })
  162. }
  163. },
  164. )
  165. const initDictionary = () => {
  166. DictionaryStore.initModelProvides()
  167. }
  168. const initData = () => {
  169. state.loading = true
  170. pluginDetail(props.transfer.id)
  171. .then(({ data }: any) => {
  172. state.form = data
  173. })
  174. .catch(({ message }: any) => {
  175. ElMessage.error(message)
  176. })
  177. .finally(() => {
  178. state.loading = false
  179. })
  180. }
  181. const onSubmit = () => {
  182. ref_form.value
  183. .submit()
  184. .then(() => {
  185. DialogStore.confirm({
  186. content: `请确认是否提交?`,
  187. onSubmit: () => {
  188. state.loading = true
  189. if (props.transfer.mode === 'add') {
  190. pluginAddInstance(state.form)
  191. .then(() => {
  192. ElMessage.success(`${titleCpt.value}成功!`)
  193. emit('update:show', false)
  194. emit('refresh')
  195. })
  196. .catch(({ message }: any) => {
  197. ElMessage.error(message)
  198. })
  199. .finally(() => {
  200. state.loading = false
  201. })
  202. } else {
  203. pluginUpdateInstance(state.form)
  204. .then(() => {
  205. ElMessage.success(`${titleCpt.value}成功!`)
  206. emit('update:show', false)
  207. emit('refresh')
  208. })
  209. .catch(({ message }: any) => {
  210. ElMessage.error(message)
  211. })
  212. .finally(() => {
  213. state.loading = false
  214. })
  215. }
  216. },
  217. })
  218. })
  219. .catch((e) => {
  220. ElMessage({
  221. message: e[0].message,
  222. grouping: true,
  223. type: 'warning',
  224. })
  225. })
  226. }
  227. const getModelProvide = (obj) => {
  228. console.log(obj)
  229. state.form.name = obj.name
  230. state.form.description = obj.description
  231. state.baseForms = obj.basicConfigAttr
  232. ? Object.values(obj.basicConfigAttr)
  233. : []
  234. state.paramForms = obj.paramConfigAttr
  235. ? Object.values(obj.paramConfigAttr)
  236. : []
  237. state.bizForms = obj.bizConfigAttr ? Object.values(obj.bizConfigAttr) : []
  238. }
  239. </script>
  240. <style lang="scss" scoped></style>