FileProps.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <div class="props">
  3. <t-tabs v-model="data.tab">
  4. <t-tab-panel :value="1" label="画布">
  5. <t-space direction="vertical" size="small" class="panel">
  6. <div class="form-item">
  7. <label>画布尺寸</label>
  8. <t-input-number
  9. label="W"
  10. :value="data.meta2dData.width"
  11. placeholder="宽"
  12. theme="normal"
  13. min="1"
  14. style="width: 80px"
  15. @change="changeValue($event, 'width')"
  16. />
  17. <t-input-number
  18. class="ml-8"
  19. label="H"
  20. placeholder="高"
  21. theme="normal"
  22. min="1"
  23. :value="data.meta2dData.height"
  24. style="width: 80px"
  25. @change="changeValue($event, 'height')"
  26. />
  27. <t-dropdown
  28. :minColumnWidth="180"
  29. :maxHeight="500"
  30. :delay2="[10, 150]"
  31. overlayClassName="header-dropdown"
  32. >
  33. <t-icon name="more" class="ml-8 hover" />
  34. <t-dropdown-menu>
  35. <t-dropdown-item
  36. v-for="item in screenList"
  37. @click="selectedSreen(item)"
  38. >
  39. <div class="flex between">
  40. {{ item.name }}
  41. <span class="desc">
  42. {{ item.width }}
  43. <span style="font-size: 10px; margin: 0 4px">x</span>
  44. {{ item.height }}
  45. </span>
  46. </div>
  47. </t-dropdown-item>
  48. </t-dropdown-menu>
  49. </t-dropdown>
  50. </div>
  51. <div class="form-item">
  52. <label>背景颜色</label>
  53. <t-color-picker
  54. class="w-full"
  55. format="CSS"
  56. :color-modes="['monochrome']"
  57. :show-primary-color-preview="false"
  58. :value="data.meta2dData.background"
  59. @change="changeValue($event, 'background')"
  60. />
  61. </div>
  62. <div class="form-item">
  63. <label>背景图片</label>
  64. <t-upload
  65. class="ml-8"
  66. v-model="data.background"
  67. action="/api/image/upload"
  68. theme="image"
  69. accept="image/*"
  70. :headers="headers"
  71. :data="updataData"
  72. :auto-upload="true"
  73. :upload-all-files-in-one-request="false"
  74. @success="fileSuccessed"
  75. @remove="fileRemoved"
  76. />
  77. </div>
  78. </t-space>
  79. <t-space direction="vertical" size="small" class="mt-8">
  80. <t-collapse
  81. :defaultValue="['1']"
  82. expandIconPlacement="right"
  83. :borderless="true"
  84. >
  85. <t-collapse-panel value="1" header="预览设置">
  86. <t-space direction="vertical" size="small">
  87. <div class="form-item">
  88. <label>缩放方式</label>
  89. <t-radio-group class="ml-8" default-value="1">
  90. <t-radio
  91. value="1"
  92. title="宽高中较小的铺满"
  93. style="width: 200px"
  94. >
  95. 自动铺满
  96. </t-radio>
  97. <t-radio
  98. value="2"
  99. title="高度等比例缩放"
  100. style="width: 200px"
  101. >
  102. 宽度铺满
  103. </t-radio>
  104. <t-radio value="3" title="宽度等比例缩放">高度铺满</t-radio>
  105. </t-radio-group>
  106. </div>
  107. <div class="form-item">
  108. <label>显示滚动条</label>
  109. <t-checkbox v-model="data.scroll" class="ml-8" />
  110. </div>
  111. <template v-if="data.scroll">
  112. <div class="form-item">
  113. <label>水平对齐</label>
  114. <t-radio-group class="ml-8" default-value="2">
  115. <t-radio value="1" style="width: 200px">左对齐</t-radio>
  116. <t-radio value="2" style="width: 200px">居中</t-radio>
  117. <t-radio value="3" style="width: 200px">右对齐</t-radio>
  118. </t-radio-group>
  119. </div>
  120. <div class="form-item">
  121. <label>垂直对齐</label>
  122. <t-radio-group class="ml-8" default-value="2">
  123. <t-radio value="1" style="width: 200px">顶部对齐</t-radio>
  124. <t-radio value="2" style="width: 200px">居中</t-radio>
  125. <t-radio value="3" style="width: 200px">底部对齐</t-radio>
  126. </t-radio-group>
  127. </div>
  128. </template>
  129. </t-space>
  130. </t-collapse-panel>
  131. <t-collapse-panel value="2" header="进阶设置">
  132. <t-space direction="vertical" size="small">
  133. <div class="form-item">
  134. <label>初始化动作</label>
  135. <t-button
  136. variant="outline"
  137. style="padding: 0 4px; margin: 2px 8px"
  138. @click="showInitFnDialog"
  139. >
  140. <t-icon name="ellipsis" />
  141. </t-button>
  142. </div>
  143. <div class="form-item">
  144. <label>数据监听</label>
  145. <t-button
  146. variant="outline"
  147. style="padding: 0 4px; margin: 2px 8px"
  148. @click="showDataTransformation"
  149. >
  150. <t-icon name="ellipsis" />
  151. </t-button>
  152. </div>
  153. </t-space>
  154. </t-collapse-panel>
  155. </t-collapse>
  156. </t-space>
  157. </t-tab-panel>
  158. <t-tab-panel :value="2" label="结构">
  159. <ElementTree />
  160. </t-tab-panel>
  161. </t-tabs>
  162. <t-dialog
  163. v-if="initFnDialog.show"
  164. :visible="true"
  165. header="初始化动作"
  166. @confirm="onOkInitFn"
  167. @close="initFnDialog.show = false"
  168. :width="700"
  169. >
  170. <CodeEditor v-model="initFnDialog.data" style="height: 300px" />
  171. </t-dialog>
  172. <t-dialog
  173. v-if="dataTransformationDialog.show"
  174. :visible="true"
  175. header="数据监听"
  176. @confirm="onOkDataTransformation"
  177. @close="dataTransformationDialog.show = false"
  178. :width="700"
  179. >
  180. <CodeEditor
  181. v-model="dataTransformationDialog.data"
  182. style="height: 300px"
  183. />
  184. </t-dialog>
  185. </div>
  186. </template>
  187. <script lang="ts" setup>
  188. import { onMounted, reactive, onUnmounted, ref } from 'vue';
  189. import { getCookie } from '@/services/cookie';
  190. import ElementTree from './ElementTree.vue';
  191. import CodeEditor from '@/views/components/common/CodeEditor.vue';
  192. const headers = {
  193. Authorization: 'Bearer ' + (localStorage.token || getCookie('token') || ''),
  194. };
  195. const updataData = { directory: '/项目' };
  196. const data = reactive<any>({
  197. tab: 1,
  198. background: [],
  199. meta2dData: {},
  200. });
  201. const screenList = reactive([
  202. {
  203. name: '大屏',
  204. width: 1920,
  205. height: 1080,
  206. },
  207. {
  208. name: '网页',
  209. width: 1440,
  210. height: 1024,
  211. },
  212. {
  213. name: '平板12.9"',
  214. width: 1024,
  215. height: 1366,
  216. },
  217. {
  218. name: '平板11"',
  219. width: 834,
  220. height: 1194,
  221. },
  222. {
  223. name: '平板Mini',
  224. width: 768,
  225. height: 1024,
  226. },
  227. {
  228. name: '华为P8',
  229. width: 360,
  230. height: 640,
  231. },
  232. {
  233. name: '华为P40',
  234. width: 395,
  235. height: 856,
  236. },
  237. {
  238. name: '手机1',
  239. width: 430,
  240. height: 932,
  241. },
  242. {
  243. name: '手机2',
  244. width: 375,
  245. height: 812,
  246. },
  247. ]);
  248. const initFnDialog = reactive<any>({
  249. show: false,
  250. data: '',
  251. });
  252. const dataTransformationDialog = reactive<any>({
  253. show: false,
  254. data: '',
  255. });
  256. const selectedSreen = (item: any) => {
  257. meta2d.store.data.width = item.width;
  258. meta2d.store.data.height = item.height;
  259. meta2d.store.patchFlagsBackground = true;
  260. meta2d.render();
  261. openData();
  262. };
  263. const fileSuccessed = async (content: any) => {
  264. meta2d.store.patchFlagsBackground = true;
  265. meta2d.setBackgroundImage(content.response.url);
  266. meta2d.store.patchFlagsBackground = true;
  267. meta2d.render();
  268. };
  269. const fileRemoved = () => {
  270. meta2d.setBackgroundImage('');
  271. meta2d.store.patchFlagsBackground = true;
  272. meta2d.render();
  273. data.background = [];
  274. };
  275. const changeValue = (e: any, key: string) => {
  276. // @ts-ignore
  277. meta2d.store.data[key] = e;
  278. meta2d.render();
  279. openData();
  280. };
  281. onMounted(() => {
  282. openData();
  283. meta2d.on('opened', openData);
  284. });
  285. onUnmounted(() => {
  286. meta2d.off('opened', openData);
  287. });
  288. function openData() {
  289. data.meta2dData = Object.assign({}, meta2d.store.data);
  290. if (meta2d.store.data.bkImage) {
  291. data.background = [
  292. {
  293. name: meta2d.store.data.bkImage,
  294. url: meta2d.store.data.bkImage,
  295. },
  296. ];
  297. }
  298. }
  299. const showInitFnDialog = () => {
  300. initFnDialog.data = meta2d.store.data.initJs;
  301. initFnDialog.show = true;
  302. };
  303. const onOkInitFn = () => {
  304. meta2d.store.data.initJs = initFnDialog.data;
  305. initFnDialog.show = false;
  306. };
  307. const showDataTransformation = () => {
  308. dataTransformationDialog.data = meta2d.store.data.socketCbJs;
  309. dataTransformationDialog.show = true;
  310. };
  311. const onOkDataTransformation = () => {
  312. meta2d.store.data.socketCbJs = dataTransformationDialog.data;
  313. dataTransformationDialog.show = false;
  314. };
  315. </script>
  316. <style lang="postcss" scoped>
  317. .props {
  318. }
  319. </style>