FileProps.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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', '2']"
  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>
  135. 图标URL
  136. <span>
  137. <label
  138. class="vip-label"
  139. style="font-size: 10px; padding: 0 2px"
  140. >
  141. VIP
  142. </label>
  143. </span>
  144. </label>
  145. <div class="px-8" style="width: 200px">
  146. <template v-if="data.meta2dData.iconUrls">
  147. <div
  148. v-for="(icon, i) of data.meta2dData.iconUrls"
  149. class="flex middle between"
  150. style="height: 30px"
  151. >
  152. <div>
  153. {{ icon.substring(0, 8) }}...{{ icon.substr(-16) }}
  154. </div>
  155. <t-icon
  156. name="close"
  157. class="hover"
  158. @click="removeIconUrl(i)"
  159. />
  160. </div>
  161. </template>
  162. <div class="flex middle" v-if="user.isVip">
  163. <t-input
  164. v-model="data.iconUrl"
  165. placeholder="Font class方式URL"
  166. style="width: 150px; margin-left: -8px"
  167. />
  168. <t-button
  169. variant="outline"
  170. style="padding: 4px 8px; margin-left: 8px"
  171. @click="addIconUrl"
  172. >
  173. 添加
  174. </t-button>
  175. </div>
  176. <div v-else class="desc mt-4">
  177. 支持添加iconfont。
  178. <a :href="assets.account" target="_blank">VIP</a> 功能
  179. </div>
  180. </div>
  181. </div>
  182. <div class="form-item">
  183. <label>初始化动作</label>
  184. <t-button
  185. variant="outline"
  186. style="padding: 0 4px; margin: 2px 8px"
  187. @click="showInitFnDialog"
  188. >
  189. <t-icon name="ellipsis" />
  190. </t-button>
  191. </div>
  192. <div class="form-item">
  193. <label>数据监听</label>
  194. <t-button
  195. variant="outline"
  196. style="padding: 0 4px; margin: 2px 8px"
  197. @click="showDataTransformation"
  198. >
  199. <t-icon name="ellipsis" />
  200. </t-button>
  201. </div>
  202. </t-space>
  203. </t-collapse-panel>
  204. </t-collapse>
  205. </t-space>
  206. </t-tab-panel>
  207. <t-tab-panel :value="2" label="结构">
  208. <ElementTree />
  209. </t-tab-panel>
  210. </t-tabs>
  211. <t-dialog
  212. v-if="initFnDialog.show"
  213. :visible="true"
  214. header="初始化动作"
  215. @confirm="onOkInitFn"
  216. @close="initFnDialog.show = false"
  217. :width="700"
  218. >
  219. <CodeEditor v-model="initFnDialog.data" style="height: 300px" />
  220. </t-dialog>
  221. <t-dialog
  222. v-if="dataTransformationDialog.show"
  223. :visible="true"
  224. header="数据监听"
  225. @confirm="onOkDataTransformation"
  226. @close="dataTransformationDialog.show = false"
  227. :width="700"
  228. >
  229. <CodeEditor
  230. v-model="dataTransformationDialog.data"
  231. style="height: 300px"
  232. />
  233. </t-dialog>
  234. </div>
  235. </template>
  236. <script lang="ts" setup>
  237. import { onMounted, reactive, onUnmounted } from 'vue';
  238. import { useUser } from '@/services/user';
  239. import { getCookie } from '@/services/cookie';
  240. import ElementTree from './ElementTree.vue';
  241. import CodeEditor from '@/views/components/common/CodeEditor.vue';
  242. import { autoSave, inTreePanel, useAssets } from '@/services/common';
  243. import { MessagePlugin } from 'tdesign-vue-next';
  244. const headers = {
  245. Authorization: 'Bearer ' + (localStorage.token || getCookie('token') || ''),
  246. };
  247. const updataData = { directory: '/项目' };
  248. const { assets } = useAssets();
  249. const { user } = useUser();
  250. const data = reactive<any>({
  251. tab: 1,
  252. background: [],
  253. meta2dData: {},
  254. iconUrl: '',
  255. });
  256. const screenList = reactive([
  257. {
  258. name: '大屏',
  259. width: 1920,
  260. height: 1080,
  261. },
  262. {
  263. name: '网页',
  264. width: 1440,
  265. height: 1024,
  266. },
  267. {
  268. name: '平板12.9"',
  269. width: 1024,
  270. height: 1366,
  271. },
  272. {
  273. name: '平板11"',
  274. width: 834,
  275. height: 1194,
  276. },
  277. {
  278. name: '平板Mini',
  279. width: 768,
  280. height: 1024,
  281. },
  282. {
  283. name: '华为P8',
  284. width: 360,
  285. height: 640,
  286. },
  287. {
  288. name: '华为P40',
  289. width: 395,
  290. height: 856,
  291. },
  292. {
  293. name: '手机1',
  294. width: 430,
  295. height: 932,
  296. },
  297. {
  298. name: '手机2',
  299. width: 375,
  300. height: 812,
  301. },
  302. ]);
  303. const initFnDialog = reactive<any>({
  304. show: false,
  305. data: '',
  306. });
  307. const dataTransformationDialog = reactive<any>({
  308. show: false,
  309. data: '',
  310. });
  311. const selectedSreen = (item: any) => {
  312. meta2d.store.data.width = item.width;
  313. meta2d.store.data.height = item.height;
  314. meta2d.store.patchFlagsBackground = true;
  315. meta2d.render();
  316. openData();
  317. };
  318. const fileSuccessed = async (content: any) => {
  319. meta2d.store.patchFlagsBackground = true;
  320. meta2d.setBackgroundImage(content.response.url);
  321. meta2d.store.patchFlagsBackground = true;
  322. meta2d.render();
  323. };
  324. const fileRemoved = () => {
  325. meta2d.setBackgroundImage('');
  326. meta2d.store.patchFlagsBackground = true;
  327. meta2d.render();
  328. data.background = [];
  329. };
  330. const changeValue = (e: any, key: string) => {
  331. // @ts-ignore
  332. meta2d.store.data[key] = e;
  333. meta2d.render();
  334. openData();
  335. };
  336. onMounted(() => {
  337. if (inTreePanel.value) {
  338. data.tab = 2;
  339. }
  340. openData();
  341. meta2d.on('opened', openData);
  342. });
  343. onUnmounted(() => {
  344. meta2d.off('opened', openData);
  345. });
  346. function openData() {
  347. data.meta2dData = Object.assign({}, meta2d.store.data);
  348. if (meta2d.store.data.bkImage) {
  349. data.background = [
  350. {
  351. name: meta2d.store.data.bkImage,
  352. url: meta2d.store.data.bkImage,
  353. },
  354. ];
  355. }
  356. }
  357. const showInitFnDialog = () => {
  358. initFnDialog.data = meta2d.store.data.initJs;
  359. initFnDialog.show = true;
  360. };
  361. const onOkInitFn = () => {
  362. meta2d.store.data.initJs = initFnDialog.data;
  363. initFnDialog.show = false;
  364. };
  365. const showDataTransformation = () => {
  366. dataTransformationDialog.data = meta2d.store.data.socketCbJs;
  367. dataTransformationDialog.show = true;
  368. };
  369. const onOkDataTransformation = () => {
  370. meta2d.store.data.socketCbJs = dataTransformationDialog.data;
  371. dataTransformationDialog.show = false;
  372. };
  373. const addIconUrl = () => {
  374. if (!data.iconUrl || data.iconUrl.substr(-4) !== '.css') {
  375. MessagePlugin.error('请填写以.css结尾的font-class引用方式的URL地址');
  376. return;
  377. }
  378. if (!data.meta2dData.iconUrls) {
  379. data.meta2dData.iconUrls = [];
  380. }
  381. data.meta2dData.iconUrls.push(data.iconUrl);
  382. // @ts-ignore
  383. meta2d.store.data.iconUrls = data.meta2dData.iconUrls;
  384. data.iconUrl = '';
  385. autoSave(true);
  386. };
  387. const removeIconUrl = (i: number) => {
  388. data.meta2dData.iconUrls.splice(i, 1);
  389. // @ts-ignore
  390. meta2d.store.data.iconUrls = data.meta2dData.iconUrls;
  391. autoSave(true);
  392. };
  393. </script>
  394. <style lang="postcss" scoped>
  395. .props {
  396. }
  397. </style>