model-detail.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. :show-submit="!isViewCpt"
  12. >
  13. <div class="bm-form">
  14. <CzrForm ref="ref_form" :form-view="isViewCpt">
  15. <CzrFormColumn
  16. required
  17. :span="8"
  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="8"
  28. label="模型供应商"
  29. v-model:param="state.form.manufacturer"
  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 v-if="state.form.manufacturer">
  39. <CzrFormColumn
  40. :span="8"
  41. label="版本"
  42. v-model:param="state.form.version"
  43. :disabled="true"
  44. />
  45. <CzrFormColumn
  46. required
  47. :span="24"
  48. label="模型名称"
  49. v-model:param="state.form.name"
  50. />
  51. <CzrFormColumn
  52. required
  53. :span="24"
  54. label="模型简介"
  55. v-model:param="state.form.synopsis"
  56. type="textarea"
  57. :rows="4"
  58. />
  59. <CzrFormColumn
  60. required
  61. :span="24"
  62. label="详细介绍"
  63. v-model:param="state.form.overview"
  64. link="markdown"
  65. height="400px"
  66. />
  67. </template>
  68. </template>
  69. </CzrForm>
  70. </div>
  71. </CzrDialog>
  72. </template>
  73. <script setup lang="ts">
  74. import {
  75. computed,
  76. getCurrentInstance,
  77. nextTick,
  78. reactive,
  79. ref,
  80. watch,
  81. } from 'vue'
  82. import { ElMessage, ElMessageBox } from 'element-plus'
  83. import {
  84. useAppStore,
  85. useDialogStore,
  86. useDictionaryStore,
  87. useRegexStore,
  88. } from '@/stores'
  89. import { useRouter } from 'vue-router'
  90. import {
  91. modelManageGetModelManageById,
  92. modelManageSaveModelManage,
  93. modelManageUpdateModelManage,
  94. } from '@/api/modules/center/square'
  95. const router = useRouter()
  96. const AppStore = useAppStore()
  97. const DictionaryStore = useDictionaryStore()
  98. const DialogStore = useDialogStore()
  99. const RegexStore = useRegexStore()
  100. const emit = defineEmits(['update:show', 'refresh'])
  101. const { proxy } = getCurrentInstance()
  102. const props = defineProps({
  103. show: { default: false },
  104. transfer: <any>{},
  105. })
  106. const state: any = reactive({
  107. loading: false,
  108. form: {},
  109. })
  110. const ref_form = ref()
  111. const titleCpt = computed(() => {
  112. let t = ''
  113. switch (props.transfer.mode) {
  114. case 'add':
  115. t = '新增' + t
  116. break
  117. case 'edit':
  118. t = '编辑' + t
  119. break
  120. case 'view':
  121. t = '查看' + t
  122. break
  123. }
  124. return t
  125. })
  126. const isViewCpt = computed(() => props.transfer?.mode === 'view')
  127. watch(
  128. () => props.show,
  129. (n) => {
  130. if (n) {
  131. initDictionary()
  132. state.form = {
  133. state: 0,
  134. }
  135. if (props.transfer.mode !== 'add') {
  136. initData()
  137. }
  138. nextTick(() => {
  139. ref_form.value.reset()
  140. })
  141. }
  142. },
  143. )
  144. const initDictionary = () => {
  145. DictionaryStore.initModelTypes()
  146. DictionaryStore.initModelProvides()
  147. }
  148. const initData = () => {
  149. state.loading = true
  150. modelManageGetModelManageById({ id: props.transfer.id })
  151. .then(({ data }: any) => {
  152. state.form = data
  153. })
  154. .catch(() => {})
  155. .finally(() => {
  156. state.loading = false
  157. })
  158. }
  159. const onSubmit = () => {
  160. ref_form.value
  161. .submit()
  162. .then(() => {
  163. DialogStore.confirm({
  164. content: `请确认是否提交?`,
  165. onSubmit: () => {
  166. state.loading = true
  167. if (props.transfer.mode === 'add') {
  168. modelManageSaveModelManage(state.form)
  169. .then(({ data }: any) => {
  170. ElMessage.success(`${titleCpt.value}成功!`)
  171. emit('update:show', false)
  172. emit('refresh')
  173. })
  174. .catch(() => {})
  175. .finally(() => {
  176. state.loading = false
  177. })
  178. } else {
  179. modelManageUpdateModelManage(state.form)
  180. .then(({ data }: any) => {
  181. ElMessage.success(`${titleCpt.value}成功!`)
  182. emit('update:show', false)
  183. emit('refresh')
  184. })
  185. .catch(() => {})
  186. .finally(() => {
  187. state.loading = false
  188. })
  189. }
  190. },
  191. })
  192. })
  193. .catch((e) => {
  194. ElMessage({
  195. message: e[0].message,
  196. grouping: true,
  197. type: 'warning',
  198. })
  199. })
  200. }
  201. const getModelProvide = (obj) => {
  202. console.log(obj)
  203. state.form.name = obj.name
  204. state.form.version = obj.version
  205. state.form.synopsis = obj.description
  206. state.form.overview = obj.description
  207. }
  208. </script>
  209. <style lang="scss" scoped></style>