xm-solid-radio.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <div>
  3. <a-form-model-item>
  4. <div slot="label">
  5. 选项
  6. <a-icon
  7. v-if="component.attrFD.listItemType !== 'dict'"
  8. type="plus-circle"
  9. theme="twoTone"
  10. @click="addItem"
  11. />
  12. <a-select
  13. v-model="component.attrFD.listItemType"
  14. @change="
  15. () => {
  16. if (component.attrFD.listItemType !== 'dict') {
  17. // 优先看有没有配数据字典,配了数据字典就从数据字典取,没有就从自定义的取
  18. component.attr.dict = undefined
  19. }
  20. }
  21. "
  22. >
  23. <a-select-option value="dict">
  24. 数据字典
  25. </a-select-option>
  26. <a-select-option value="custom">
  27. 自定义
  28. </a-select-option>
  29. </a-select>
  30. </div>
  31. <template v-if="component.attrFD.listItemType !== 'dict'">
  32. <div v-for="(item, index) in component.attr.selectListItem" :key="index">
  33. <a-col :span="9"><a-input v-model="item.label" placeholder="名称"/></a-col>
  34. <a-col :span="9"><a-input v-model="item.value" placeholder="值"/></a-col>
  35. <a-col :span="6">
  36. <a-icon type="delete" @click="deleteItem(index)" />
  37. </a-col>
  38. </div>
  39. </template>
  40. <sd-tree-picker
  41. v-else
  42. v-model="component.attr.dict"
  43. single
  44. :load-tree-data="loadTreeData"
  45. :render="renderItem"
  46. option-label="text"
  47. :search-tree-data="searchTreeData"
  48. @change="updateSelectListItem"
  49. />
  50. </a-form-model-item>
  51. <a-form-model-item label="默认值">
  52. <SdUglySelect
  53. v-model="component.attr.defaultValue"
  54. allow-clear
  55. :options="component.attr.selectListItem"
  56. />
  57. </a-form-model-item>
  58. </div>
  59. </template>
  60. <script>
  61. import SdUglySelect from '@/form-designer/sd-ugly-select.vue'
  62. import { Radio } from 'ant-design-vue'
  63. import axios from '@/common/services/axios-instance'
  64. import components from './_import-components/xm-solid-radio-import'
  65. function getComponentForEdit(component, childrenComponent) {
  66. return {
  67. props: ['designerData'],
  68. render() {
  69. const defaultValue = this.designerData.attr.defaultValue
  70. return (
  71. <component defaultValue={defaultValue} buttonStyle={'solid'}>
  72. {this.designerData.attr.selectListItem.map((item) => {
  73. return <childrenComponent value={item.value}>{item.label}</childrenComponent>
  74. })}
  75. </component>
  76. )
  77. },
  78. }
  79. }
  80. export const metaInfo = {
  81. caption: '实底单选框',
  82. component: getComponentForEdit(Radio.Group, Radio.Button),
  83. icon: 'sd-square',
  84. order: 800,
  85. category: 'basic',
  86. }
  87. export { getComponentForEdit }
  88. export const fieldProps = {
  89. dataType: 'selectlist',
  90. attrFD: { listItemType: 'custom' },
  91. attr: {
  92. dict: undefined,
  93. selectListItem: [
  94. {
  95. label: '选项1',
  96. value: '1',
  97. },
  98. {
  99. label: '选项2',
  100. value: '2',
  101. },
  102. ],
  103. },
  104. }
  105. export default {
  106. name: 'XmSolidRadio',
  107. components: { SdUglySelect, ...components },
  108. data() {
  109. return {}
  110. },
  111. methods: {
  112. addItem() {
  113. this.component.attr.selectListItem.push({
  114. label: '选项',
  115. value: 'new',
  116. })
  117. },
  118. deleteItem(index) {
  119. this.component.attr.selectListItem.splice(index, 1)
  120. },
  121. loadTreeData(id) {
  122. // 需求约定的,数据字典从这两类配置参数下面取
  123. return Promise.all([
  124. axios.get('api/framework/v1/dict-manager/dictTree?keyId=OA_COMMON&containChildren=true'),
  125. axios.get('api/framework/v1/dict-manager/dictTree?keyId=GENERAL&containChildren=true'),
  126. ]).then((res) => {
  127. const data = [
  128. {
  129. id: 'OA_COMMON',
  130. text: '公用',
  131. leaf: false,
  132. props: {},
  133. children: res[0].data,
  134. },
  135. {
  136. id: 'GENERAL',
  137. text: '通用审批框架',
  138. leaf: false,
  139. props: {},
  140. children: res[1].data,
  141. },
  142. ]
  143. const f = function(data) {
  144. if (data?.length) {
  145. data.forEach((item) => {
  146. item.isLeaf = item.leaf
  147. item.checkable = item.leaf
  148. f(item.children)
  149. })
  150. }
  151. }
  152. f(data)
  153. this.treeData = data
  154. return data
  155. })
  156. },
  157. searchTreeData(text) {
  158. const result = []
  159. const f = function(data) {
  160. if (data?.length) {
  161. data.forEach((item) => {
  162. if (item.text.includes(text)) {
  163. result.push(item)
  164. }
  165. f(item.children)
  166. })
  167. }
  168. }
  169. f(this.treeData)
  170. return result
  171. },
  172. renderItem(item) {
  173. if (item.props) {
  174. const label = Object.keys(item.props)
  175. .map((key) => item.props[key])
  176. .join('|')
  177. return <span title={'选项:' + label}>{item.text}</span>
  178. } else {
  179. return item.text
  180. }
  181. },
  182. updateSelectListItem([item]) {
  183. if (item === undefined) {
  184. this.component.attr.selectListItem = []
  185. return
  186. }
  187. this.component.attr.dict = [{ id: item.id, text: item.text }]
  188. this.component.attr.selectListItem = []
  189. if (item.props) {
  190. Object.keys(item.props).forEach((key) => {
  191. this.component.attr.selectListItem.push({ label: item.props[key], value: key })
  192. })
  193. }
  194. },
  195. },
  196. }
  197. </script>
  198. <style module lang="scss">
  199. @use '@/common/design' as *;
  200. </style>