relation-main.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <CusDialog
  3. :show="show"
  4. :title="titleCpt"
  5. @onClose="$emit('update:show', false)"
  6. width="60%"
  7. max-height="80%"
  8. @onSubmit="onSubmit"
  9. :loading="state.loading"
  10. >
  11. <div class="__cus-dialog-form">
  12. <CusForm ref="ref_form" label-width="100px">
  13. <CusFormColumn
  14. :span="24"
  15. required
  16. label="主字段"
  17. v-model:param="state.form.mainParam"
  18. link="select"
  19. :options="state.textOptions"
  20. />
  21. <CusFormColumn
  22. :span="24"
  23. label="标签字段"
  24. v-model:param="state.form.tagParams"
  25. link="select"
  26. :options="state.textOptions"
  27. multiple
  28. />
  29. <CusFormColumn
  30. :span="24"
  31. label="副字段"
  32. v-model:param="state.form.subParams"
  33. link="select"
  34. :options="state.textOptions"
  35. multiple
  36. />
  37. <CusFormColumn
  38. :span="24"
  39. label="图片字段"
  40. v-model:param="state.form.imgParam"
  41. link="select"
  42. :options="state.textOptions"
  43. />
  44. <CusFormColumn
  45. :span="24"
  46. label="其他字段"
  47. v-model:param="state.form.otherParams"
  48. link="select"
  49. :options="state.textOptions"
  50. multiple
  51. />
  52. </CusForm>
  53. </div>
  54. </CusDialog>
  55. </template>
  56. <script setup lang="ts">
  57. import {computed, getCurrentInstance, nextTick, reactive, ref, watch} from "vue";
  58. import {useDictionaryStore} from "@/stores";
  59. import {ElMessage, ElMessageBox} from "element-plus";
  60. import {sysThemeFind, sysThemeIndexMainConfig, sysThemeStyleConfig} from "@/api/modules/manage/theme";
  61. import {sysIndexFieldList} from "@/api/modules/manage";
  62. const emit = defineEmits(['update:show', 'refresh'])
  63. const {proxy} = getCurrentInstance()
  64. const DictionaryStore = useDictionaryStore()
  65. const props = defineProps({
  66. show: {default: false},
  67. transfer: {}
  68. })
  69. const state: any = reactive({
  70. form: {},
  71. loading: false,
  72. textOptions: []
  73. })
  74. const ref_form = ref()
  75. const titleCpt = computed(() => {
  76. let t = '索引构成-主配置'
  77. return t
  78. })
  79. const onSubmit = () => {
  80. ref_form.value.submit().then(() => {
  81. ElMessageBox.confirm("是否提交?", "提示", {
  82. confirmButtonText: "确定",
  83. cancelButtonText: "取消",
  84. type: "warning",
  85. } as any).then(() => {
  86. state.loading = true
  87. const params = JSON.parse(JSON.stringify(state.form))
  88. params.otherParams = params.otherParams.map(v => {
  89. const obj = state.textOptions.filter(t => t.fieldKey == v)[0]
  90. return {
  91. label: obj.fieldName,
  92. value: obj.fieldKey
  93. }
  94. })
  95. sysThemeIndexMainConfig({
  96. id: props.transfer.id,
  97. indexStyle: JSON.stringify(params)
  98. }).then(res => {
  99. ElMessage.success('配置成功!')
  100. emit('update:show', false)
  101. emit('refresh')
  102. state.loading = false
  103. })
  104. }).catch(() => {})
  105. }).catch((e) => {
  106. ElMessage({
  107. message: e[0].message,
  108. grouping: true,
  109. type: 'warning',
  110. })
  111. })
  112. }
  113. const initDetail = () => {
  114. if (props.transfer.indexStyle) {
  115. state.form = JSON.parse(props.transfer.indexStyle)
  116. state.form.otherParams = state.form.otherParams.map(v => v.value)
  117. } else {
  118. state.form = {
  119. mainParam: '',
  120. tagParams: [],
  121. subParams: [],
  122. imgParam: '',
  123. otherParams: []
  124. }
  125. }
  126. }
  127. const initText = () => {
  128. sysIndexFieldList(proxy.$util.formatGetParam({
  129. indexId: props.transfer.indexId,
  130. type: props.transfer.type
  131. })).then(res => {
  132. state.textOptions = res.data.map(v => {
  133. v.dictLabel = v.fieldName
  134. v.dictValue = v.fieldKey
  135. return v
  136. })
  137. })
  138. }
  139. watch(() => props.show, (n) => {
  140. if (n) {
  141. initText()
  142. initDetail()
  143. nextTick(() => {
  144. ref_form.value.reset()
  145. })
  146. }
  147. })
  148. </script>
  149. <style lang="scss" scoped>
  150. </style>