FileProps.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. <more-icon class="ml-8 hover"/>
  34. <!-- <t-icon name="more" class="ml-8 hover" /> -->
  35. <t-dropdown-menu>
  36. <t-dropdown-item
  37. v-for="item in screenList"
  38. @click="selectedSreen(item)"
  39. >
  40. <div class="flex between">
  41. {{ item.name }}
  42. <span class="desc">
  43. {{ item.width }}
  44. <span style="font-size: 10px; margin: 0 4px">x</span>
  45. {{ item.height }}
  46. </span>
  47. </div>
  48. </t-dropdown-item>
  49. </t-dropdown-menu>
  50. </t-dropdown>
  51. </div>
  52. <div class="form-item">
  53. <label>背景颜色</label>
  54. <t-color-picker
  55. class="w-full"
  56. format="CSS"
  57. :recent-colors="null"
  58. :enable-alpha="true"
  59. :swatch-colors="defaultPureColor"
  60. :color-modes="['monochrome']"
  61. :show-primary-color-preview="false"
  62. v-model="data.meta2dData.background"
  63. @change="changeValue($event, 'background')"
  64. />
  65. </div>
  66. <div class="form-item">
  67. <label>背景图片</label>
  68. <t-upload
  69. class="ml-8"
  70. v-model="data.background"
  71. action="/api/image/upload"
  72. theme="image"
  73. accept="image/*"
  74. :headers="headers"
  75. :data="updataData"
  76. :auto-upload="true"
  77. :before-upload="beforeUpload"
  78. :upload-all-files-in-one-request="false"
  79. @success="fileSuccessed"
  80. @remove="fileRemoved"
  81. />
  82. </div>
  83. </t-space>
  84. <t-space direction="vertical" size="small" class="mt-8">
  85. <t-collapse
  86. :defaultValue="['1', '2']"
  87. expandIconPlacement="right"
  88. :borderless="true"
  89. >
  90. <t-collapse-panel value="1" header="预览设置">
  91. <t-space direction="vertical" size="small">
  92. <div class="form-item">
  93. <label>缩放方式</label>
  94. <t-radio-group
  95. class="ml-8"
  96. v-model="data.meta2dData.scaleMode"
  97. @change="changeValue($event, 'scaleMode')"
  98. >
  99. <t-radio
  100. value="1"
  101. title="宽高中较小的铺满"
  102. style="width: 200px"
  103. >
  104. 自动铺满
  105. </t-radio>
  106. <t-radio
  107. value="2"
  108. title="高度等比例缩放"
  109. style="width: 200px"
  110. >
  111. 宽度铺满
  112. </t-radio>
  113. <t-radio value="3" title="宽度等比例缩放">高度铺满</t-radio>
  114. </t-radio-group>
  115. </div>
  116. <div class="form-item">
  117. <label>显示滚动条</label>
  118. <t-checkbox
  119. v-model="data.meta2dData.scroll"
  120. @change="changeValue($event, 'scroll')"
  121. class="ml-8"
  122. />
  123. </div>
  124. <div class="form-item">
  125. <label>禁止移动</label>
  126. <t-checkbox
  127. v-model="data.meta2dData.isDisableTranslate"
  128. @change="changeValue($event, 'isDisableTranslate')"
  129. class="ml-8"
  130. />
  131. </div>
  132. <div class="form-item">
  133. <label>禁止缩放</label>
  134. <t-checkbox
  135. v-model="data.meta2dData.isDisableScale"
  136. @change="changeValue($event, 'isDisableScale')"
  137. class="ml-8"
  138. />
  139. </div>
  140. <!-- <template v-if="data.scroll">
  141. <div class="form-item">
  142. <label>水平对齐</label>
  143. <t-radio-group class="ml-8" default-value="2">
  144. <t-radio value="1" style="width: 200px">左对齐</t-radio>
  145. <t-radio value="2" style="width: 200px">居中</t-radio>
  146. <t-radio value="3" style="width: 200px">右对齐</t-radio>
  147. </t-radio-group>
  148. </div>
  149. <div class="form-item">
  150. <label>垂直对齐</label>
  151. <t-radio-group class="ml-8" default-value="2">
  152. <t-radio value="1" style="width: 200px">顶部对齐</t-radio>
  153. <t-radio value="2" style="width: 200px">居中</t-radio>
  154. <t-radio value="3" style="width: 200px">底部对齐</t-radio>
  155. </t-radio-group>
  156. </div>
  157. </template> -->
  158. </t-space>
  159. </t-collapse-panel>
  160. <t-collapse-panel value="2" header="进阶设置">
  161. <t-space direction="vertical" size="small">
  162. <div class="form-item">
  163. <label>
  164. 图标URL
  165. <span>
  166. <label
  167. class="vip-label"
  168. style="font-size: 10px; padding: 0 2px"
  169. >
  170. VIP
  171. </label>
  172. </span>
  173. </label>
  174. <div class="px-8" style="width: 200px">
  175. <template v-if="data.meta2dData.iconUrls">
  176. <div
  177. v-for="(icon, i) of data.meta2dData.iconUrls"
  178. class="flex middle between"
  179. style="height: 30px"
  180. >
  181. <div>
  182. {{ icon.substring(0, 8) }}...{{ icon.substr(-16) }}
  183. </div>
  184. <close-icon class="hover"
  185. @click="removeIconUrl(i)"/>
  186. <!-- <t-icon
  187. name="close"
  188. class="hover"
  189. @click="removeIconUrl(i)"
  190. /> -->
  191. </div>
  192. </template>
  193. <div class="flex middle" v-if="user.vip">
  194. <t-input
  195. v-model="data.iconUrl"
  196. placeholder="Font class方式URL"
  197. style="width: 150px; margin-left: -8px"
  198. />
  199. <t-button
  200. variant="outline"
  201. style="padding: 4px 8px; margin-left: 8px"
  202. @click="addIconUrl"
  203. >
  204. 添加
  205. </t-button>
  206. </div>
  207. <div v-else class="desc mt-4">
  208. 支持添加iconfont。
  209. <a :href="(getEnterprise as any).account" target="_blank">VIP</a>
  210. 功能
  211. </div>
  212. </div>
  213. </div>
  214. <div class="form-item">
  215. <label>初始化动作</label>
  216. <t-button
  217. variant="outline"
  218. style="padding: 0 4px; margin: 2px 8px"
  219. @click="showInitFnDialog"
  220. >
  221. <ellipsis-icon />
  222. <!-- <t-icon name="ellipsis" /> -->
  223. </t-button>
  224. </div>
  225. <div class="form-item">
  226. <label>数据监听</label>
  227. <t-button
  228. variant="outline"
  229. style="padding: 0 4px; margin: 2px 8px"
  230. @click="showDataTransformation"
  231. >
  232. <ellipsis-icon />
  233. <!-- <t-icon name="ellipsis" /> -->
  234. </t-button>
  235. </div>
  236. </t-space>
  237. </t-collapse-panel>
  238. </t-collapse>
  239. </t-space>
  240. </t-tab-panel>
  241. <t-tab-panel :value="2" label="结构">
  242. <ElementTree />
  243. </t-tab-panel>
  244. </t-tabs>
  245. <t-dialog
  246. v-if="initFnDialog.show"
  247. :visible="true"
  248. header="初始化动作"
  249. @confirm="onOkInitFn"
  250. @close="initFnDialog.show = false"
  251. :width="700"
  252. >
  253. <CodeEditor v-model="initFnDialog.data" style="height: 300px" />
  254. </t-dialog>
  255. <t-dialog
  256. v-if="dataTransformationDialog.show"
  257. :visible="true"
  258. header="数据监听"
  259. @confirm="onOkDataTransformation"
  260. @close="dataTransformationDialog.show = false"
  261. :width="700"
  262. >
  263. <CodeEditor
  264. v-model="dataTransformationDialog.data"
  265. style="height: 300px"
  266. />
  267. </t-dialog>
  268. </div>
  269. </template>
  270. <script lang="ts" setup>
  271. import { onMounted, reactive, onUnmounted } from 'vue';
  272. import { useUser } from '@/services/user';
  273. import { getCookie } from '@/services/cookie';
  274. import ElementTree from './ElementTree.vue';
  275. import CodeEditor from '@/views/components/common/CodeEditor.vue';
  276. import { autoSave, inTreePanel, useAssets } from '@/services/common';
  277. import { MessagePlugin } from 'tdesign-vue-next';
  278. import { loadCss } from '@meta2d/core';
  279. import { defaultPureColor } from '@/services/defaults';
  280. import { useEnterprise } from '@/services/enterprise';
  281. import { MoreIcon, CloseIcon, EllipsisIcon} from 'tdesign-icons-vue-next';
  282. const { getEnterprise } = useEnterprise();
  283. const headers = {
  284. Authorization: 'Bearer ' + (localStorage.token || getCookie('token') || ''),
  285. };
  286. const updataData = { directory: '/大屏/图片/默认' };
  287. // const { assets } = useAssets();
  288. const { user } = useUser();
  289. const data = reactive<any>({
  290. tab: 1,
  291. background: [],
  292. meta2dData: {},
  293. iconUrl: '',
  294. });
  295. const screenList = reactive([
  296. {
  297. name: '大屏',
  298. width: 1920,
  299. height: 1080,
  300. },
  301. {
  302. name: '网页',
  303. width: 1440,
  304. height: 1024,
  305. },
  306. {
  307. name: '平板12.9"',
  308. width: 1024,
  309. height: 1366,
  310. },
  311. {
  312. name: '平板11"',
  313. width: 834,
  314. height: 1194,
  315. },
  316. {
  317. name: '平板Mini',
  318. width: 768,
  319. height: 1024,
  320. },
  321. {
  322. name: '华为P8',
  323. width: 360,
  324. height: 640,
  325. },
  326. {
  327. name: '华为P40',
  328. width: 395,
  329. height: 856,
  330. },
  331. {
  332. name: '手机1',
  333. width: 430,
  334. height: 932,
  335. },
  336. {
  337. name: '手机2',
  338. width: 375,
  339. height: 812,
  340. },
  341. ]);
  342. const initFnDialog = reactive<any>({
  343. show: false,
  344. data: '',
  345. });
  346. const dataTransformationDialog = reactive<any>({
  347. show: false,
  348. data: '',
  349. });
  350. const selectedSreen = (item: any) => {
  351. meta2d.store.data.width = item.width;
  352. meta2d.store.data.height = item.height;
  353. // meta2d.store.patchFlagsBackground = true;
  354. meta2d.canvas.canvasTemplate.bgPatchFlags = true;
  355. meta2d.render();
  356. openData();
  357. };
  358. const beforeUpload = (file: any) => {
  359. if (!(user && user.id)) {
  360. MessagePlugin.warning('请先登录!');
  361. return false;
  362. }
  363. return true;
  364. };
  365. const fileSuccessed = async (content: any) => {
  366. // meta2d.store.patchFlagsBackground = true;
  367. meta2d.setBackgroundImage(content.response.url);
  368. setTimeout(() => {
  369. // meta2d.store.patchFlagsBackground = true;
  370. meta2d.render();
  371. }, 1000);
  372. };
  373. const fileRemoved = () => {
  374. meta2d.setBackgroundImage('');
  375. // meta2d.store.patchFlagsBackground = true;
  376. meta2d.render();
  377. data.background = [];
  378. };
  379. const changeValue = (e: any, key: string) => {
  380. // @ts-ignore
  381. meta2d.store.data[key] = e;
  382. if (key === 'background') {
  383. // meta2d.store.patchFlagsBackground = true;
  384. meta2d.setBackgroundColor(e);
  385. } else if (key === 'width' || key === 'height') {
  386. meta2d.canvas.canvasTemplate.bgPatchFlags = true;
  387. }
  388. meta2d.render();
  389. openData();
  390. };
  391. onMounted(() => {
  392. if (inTreePanel.value) {
  393. data.tab = 2;
  394. }
  395. openData();
  396. meta2d.on('opened', openData);
  397. });
  398. onUnmounted(() => {
  399. meta2d.off('opened', openData);
  400. });
  401. function openData() {
  402. if (!(meta2d.store.data as any).scaleMode) {
  403. (meta2d.store.data as any).scaleMode = '1';
  404. }
  405. data.meta2dData = Object.assign({}, meta2d.store.data);
  406. if (meta2d.store.data.bkImage) {
  407. data.background = [
  408. {
  409. name: meta2d.store.data.bkImage,
  410. url: meta2d.store.data.bkImage,
  411. },
  412. ];
  413. }
  414. }
  415. const showInitFnDialog = () => {
  416. initFnDialog.data = meta2d.store.data.initJs;
  417. initFnDialog.show = true;
  418. };
  419. const onOkInitFn = () => {
  420. meta2d.store.data.initJs = initFnDialog.data;
  421. initFnDialog.show = false;
  422. };
  423. const showDataTransformation = () => {
  424. dataTransformationDialog.data = meta2d.store.data.socketCbJs;
  425. dataTransformationDialog.show = true;
  426. };
  427. const onOkDataTransformation = () => {
  428. meta2d.store.data.socketCbJs = dataTransformationDialog.data;
  429. meta2d.listenSocket();
  430. dataTransformationDialog.show = false;
  431. };
  432. const addIconUrl = () => {
  433. if (!data.iconUrl || data.iconUrl.substr(-4) !== '.css') {
  434. MessagePlugin.error('请填写以.css结尾的font-class引用方式的URL地址');
  435. return;
  436. }
  437. if (!data.meta2dData.iconUrls) {
  438. data.meta2dData.iconUrls = [];
  439. }
  440. data.meta2dData.iconUrls.push(data.iconUrl);
  441. // @ts-ignore
  442. meta2d.store.data.iconUrls = data.meta2dData.iconUrls;
  443. if (meta2d.store.data.iconUrls) {
  444. for (const item of meta2d.store.data.iconUrls) {
  445. loadCss(item);
  446. }
  447. }
  448. data.iconUrl = '';
  449. autoSave(true);
  450. };
  451. const removeIconUrl = (i: number) => {
  452. data.meta2dData.iconUrls.splice(i, 1);
  453. // @ts-ignore
  454. meta2d.store.data.iconUrls = data.meta2dData.iconUrls;
  455. autoSave(true);
  456. };
  457. </script>
  458. <style lang="postcss" scoped>
  459. .props {
  460. }
  461. </style>