index.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. import Image from './Image.vue'
  2. import icon from '../assets/icon/icon_4image.svg'
  3. import { flagOptions, stateOptions, stateList } from '@/constants'
  4. import type { IComponentModelConfig } from '../type'
  5. import i18n from '@/locales'
  6. import { getImageByPath } from '@/utils'
  7. import { useProjectStore } from '@/store/modules/project'
  8. export default {
  9. label: i18n.global.t('image'),
  10. icon,
  11. component: Image,
  12. key: 'lv_image',
  13. group: i18n.global.t('basic'),
  14. sort: 1,
  15. hasChildren: false,
  16. parts: [
  17. {
  18. name: 'main',
  19. stateList
  20. }
  21. ],
  22. defaultSchema: {
  23. name: 'image',
  24. props: {
  25. x: 0,
  26. y: 0,
  27. width: 100,
  28. height: 100,
  29. flags: [],
  30. states: [],
  31. image: '',
  32. center: {
  33. x: 50,
  34. y: 50
  35. },
  36. rotate: 0,
  37. openScale: false,
  38. scale: 256
  39. // antiAliasing: false
  40. },
  41. styles: [
  42. {
  43. part: {
  44. name: 'main',
  45. state: 'default'
  46. },
  47. background: {
  48. color: '#ffffff00',
  49. image: {
  50. imgId: '',
  51. recolor: '#ffffff00',
  52. alpha: 255
  53. }
  54. },
  55. imageStyle: {
  56. recolor: '#ffffff00',
  57. alpha: 255
  58. },
  59. border: {
  60. color: '#000000ff',
  61. width: 0,
  62. radius: 0,
  63. side: ['all']
  64. },
  65. outline: {
  66. color: '#000000ff',
  67. width: 0,
  68. pad: 0
  69. },
  70. shadow: {
  71. color: '#2092f5ff',
  72. offsetX: 0,
  73. offsetY: 0,
  74. spread: 0,
  75. width: 0
  76. },
  77. transform: {
  78. width: 0,
  79. height: 0,
  80. translateX: 0,
  81. translateY: 0,
  82. originX: 0,
  83. originY: 0,
  84. rotate: 0,
  85. scale: 256
  86. }
  87. }
  88. ]
  89. },
  90. config: {
  91. // 组件属性
  92. props: [
  93. {
  94. label: '名称',
  95. field: 'name',
  96. valueType: 'text',
  97. componentProps: {
  98. placeholder: '请输入名称',
  99. type: 'text'
  100. }
  101. },
  102. {
  103. label: '位置/大小',
  104. valueType: 'group',
  105. children: [
  106. {
  107. label: '',
  108. field: 'props.x',
  109. valueType: 'number',
  110. componentProps: {
  111. span: 12,
  112. min: -10000,
  113. max: 10000
  114. },
  115. slots: { prefix: 'X' }
  116. },
  117. {
  118. label: '',
  119. field: 'props.y',
  120. valueType: 'number',
  121. componentProps: {
  122. span: 12,
  123. min: -10000,
  124. max: 10000
  125. },
  126. slots: { prefix: 'Y' }
  127. },
  128. {
  129. label: '',
  130. field: 'props.width',
  131. valueType: 'number',
  132. componentProps: {
  133. span: 12,
  134. min: 1,
  135. max: 10000
  136. },
  137. slots: { prefix: 'W' }
  138. },
  139. {
  140. label: '',
  141. field: 'props.height',
  142. valueType: 'number',
  143. componentProps: {
  144. span: 12,
  145. min: 1,
  146. max: 10000
  147. },
  148. slots: { prefix: 'H' }
  149. }
  150. ]
  151. },
  152. {
  153. label: '标识',
  154. field: 'props.flags',
  155. valueType: 'checkbox',
  156. componentProps: {
  157. options: flagOptions,
  158. defaultCollapsed: true
  159. }
  160. },
  161. {
  162. label: '状态',
  163. field: 'props.states',
  164. valueType: 'checkbox',
  165. componentProps: {
  166. options: stateOptions,
  167. defaultCollapsed: true
  168. }
  169. }
  170. ],
  171. coreProps: [
  172. {
  173. label: '图片',
  174. field: 'props.image',
  175. valueType: 'image',
  176. componentProps: {
  177. onValueChange: (value: string, formData: any) => {
  178. // 选中图片后获取图片信息
  179. // 根据图片信息设置控件宽高
  180. if (value) {
  181. const projectStore = useProjectStore()
  182. const imgPath = projectStore.project?.resources.images.find(
  183. (item) => item.id === value
  184. )?.path
  185. if (imgPath) {
  186. getImageByPath(projectStore.projectPath + imgPath).then((res) => {
  187. if (res?.dimensions.height) {
  188. formData.props.height = res.dimensions.height
  189. formData.props.width = res.dimensions.width
  190. }
  191. })
  192. }
  193. }
  194. }
  195. }
  196. },
  197. {
  198. label: '中心',
  199. valueType: 'group',
  200. children: [
  201. {
  202. label: 'X',
  203. field: 'props.center.x',
  204. valueType: 'number',
  205. componentProps: {
  206. span: 12
  207. }
  208. },
  209. {
  210. label: 'Y',
  211. field: 'props.center.y',
  212. valueType: 'number',
  213. componentProps: {
  214. span: 12
  215. }
  216. }
  217. ]
  218. },
  219. {
  220. label: '旋转角度',
  221. field: 'props.rotate',
  222. labelWidth: '60px',
  223. valueType: 'number',
  224. componentProps: {
  225. min: -360,
  226. max: 360
  227. }
  228. },
  229. {
  230. label: '缩放',
  231. field: 'props.openScale',
  232. labelWidth: '60px',
  233. valueType: 'switch'
  234. },
  235. {
  236. valueType: 'dependency',
  237. name: ['props.openScale'],
  238. dependency: (dependency) => {
  239. return dependency?.['props.openScale']
  240. ? [
  241. {
  242. label: '缩放值',
  243. field: 'props.scale',
  244. valueType: 'number',
  245. componentProps: {
  246. min: 0,
  247. max: 10000
  248. }
  249. }
  250. ]
  251. : []
  252. }
  253. }
  254. // {
  255. // label: '抗锯齿',
  256. // field: 'props.antiAliasing',
  257. // valueType: 'switch'
  258. // }
  259. ],
  260. // 组件样式
  261. styles: [
  262. {
  263. label: '模块/状态',
  264. field: 'part',
  265. valueType: 'part'
  266. },
  267. {
  268. label: '背景',
  269. field: 'background',
  270. valueType: 'background'
  271. },
  272. {
  273. label: '图片',
  274. field: 'imageStyle',
  275. valueType: 'imageStyle'
  276. },
  277. {
  278. label: '边框',
  279. field: 'border',
  280. valueType: 'border'
  281. },
  282. {
  283. label: '轮廓',
  284. field: 'outline',
  285. valueType: 'outline'
  286. },
  287. {
  288. label: '阴影',
  289. field: 'shadow',
  290. valueType: 'shadow'
  291. },
  292. {
  293. label: '变换',
  294. field: 'transform',
  295. valueType: 'transform'
  296. }
  297. ]
  298. }
  299. } as IComponentModelConfig