FileProps.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. <template>
  2. <div class="props">
  3. <t-tabs v-model="data.tab">
  4. <t-tab-panel :value="1" :label="$t('画布')">
  5. <t-space direction="vertical" size="small" class="panel">
  6. <div v-if="isBigScreen" class="form-item">
  7. <label>{{$t('文件名')}}</label>
  8. <t-input class="w-full" :value="meta2dData.name" @change="changeName($event, 'name')" :placeholder="$t('文件名')"></t-input>
  9. </div>
  10. <div class="form-item">
  11. <label>{{$t('分类')}}</label>
  12. <t-select v-model="data.meta2dData.case" @change="changeValue($event, 'case')">
  13. <t-option v-for="_case in cases " :value="_case.value" :label="_case.label"> {{ _case.label }} </t-option>
  14. </t-select>
  15. </div>
  16. <t-divider style="margin-left: -16px;width: 120%; " />
  17. <div class="form-item">
  18. <label>{{$t('画布尺寸')}}</label>
  19. <t-input-number label="W" :value="data.meta2dData.width" theme="normal" min="1" style="width: 80px" @change="changeValue($event, 'width')" :placeholder="$t('宽')"></t-input-number>
  20. <t-input-number class="ml-8" label="H" theme="normal" min="1" :value="data.meta2dData.height" style="width: 80px" @change="changeValue($event, 'height')" :placeholder="$t('高')"></t-input-number>
  21. <t-dropdown :minColumnWidth="180" :maxHeight="500" :delay2="[10, 150]" overlayClassName="header-dropdown">
  22. <more-icon class="ml-8 hover"></more-icon>
  23. <!-- <t-icon name="more" class="ml-8 hover" /> -->
  24. <t-dropdown-menu>
  25. <t-dropdown-item
  26. v-for="item in screenList"
  27. @click="selectedSreen(item)"
  28. >
  29. <div class="flex between">
  30. {{ item.name }}
  31. <span class="desc">
  32. {{ item.width }}
  33. <span style="font-size: 10px; margin: 0 4px">x</span>
  34. {{ item.height }}
  35. </span>
  36. </div>
  37. </t-dropdown-item>
  38. </t-dropdown-menu>
  39. </t-dropdown>
  40. </div>
  41. <div class="form-item">
  42. <label>{{$t('背景颜色')}}</label>
  43. <t-color-picker class="w-full" format="CSS" :recent-colors="null" :enable-alpha="true" :swatch-colors="defaultPureColor" :color-modes="['monochrome']" :show-primary-color-preview="false" v-model="data.meta2dData.background" @change="changeValue($event, 'background')"></t-color-picker>
  44. </div>
  45. <div class="form-item">
  46. <label>{{$t('背景图片')}}</label>
  47. <t-upload class="ml-8" v-model="data.background" :action="`${axios.defaults.baseURL}/api/image/upload`" theme="image" accept="image/*" :headers="headers" :data="updataData" :auto-upload="true" :before-upload="beforeUpload" :upload-all-files-in-one-request="false" @success="fileSuccessed" @remove="fileRemoved"></t-upload>
  48. </div>
  49. <div class="form-item">
  50. <label>{{$t('背景网格')}}</label>
  51. <div class="flex ml-8" style="align-items:center">
  52. <t-tooltip
  53. :content="$t('开启网格')"
  54. placement="top"
  55. >
  56. <t-checkbox
  57. v-model="data.grid"
  58. @change="changeGrid($event, 'grid')"
  59. style="width: 22px"
  60. />
  61. </t-tooltip>
  62. <t-tooltip
  63. v-if="data.grid"
  64. :content="$t('网格自动对齐')"
  65. placement="top"
  66. >
  67. <t-checkbox
  68. v-model="data.autoAlignGrid"
  69. @change="changeGrid($event, 'autoAlignGrid')"
  70. style="width: 22px"
  71. />
  72. </t-tooltip>
  73. <t-tooltip
  74. v-if="data.grid"
  75. :content="$t('网格颜色')"
  76. placement="top"
  77. >
  78. <t-color-picker
  79. class="simple ml-8"
  80. format="CSS"
  81. :recent-colors="null"
  82. :enable-alpha="true"
  83. :swatch-colors="defaultPureColor"
  84. :color-modes="['monochrome']"
  85. :show-primary-color-preview="false"
  86. v-model="data.gridColor"
  87. @change="changeGrid($event, 'gridColor')"
  88. />
  89. </t-tooltip>
  90. <t-tooltip
  91. v-if="data.grid"
  92. :content="$t('网格大小')"
  93. placement="top"
  94. >
  95. <t-input-number
  96. theme="normal"
  97. v-model="data.gridSize"
  98. :min="5"
  99. :decimalPlaces="0"
  100. @change="changeGrid($event,'gridSize')"
  101. class="ml-8"
  102. style="width: 100px"
  103. />
  104. </t-tooltip>
  105. </div>
  106. </div>
  107. <div class="form-item">
  108. <label>{{$t('主题')}}</label>
  109. <t-select v-model="data.theme" :options="themeOptions" @change="changeTheme" clearable class="shrink-0" :placeholder="$t('暗黑')"></t-select>
  110. </div>
  111. </t-space>
  112. <t-space direction="vertical" size="small" class="mt-8" style="width: 100%">
  113. <t-collapse
  114. :defaultValue="['1', '2','3']"
  115. expandIconPlacement="right"
  116. :borderless="true"
  117. >
  118. <t-collapse-panel value="1" :header="$t('预览设置')">
  119. <t-space direction="vertical" size="small">
  120. <div class="form-item">
  121. <label>{{$t('缩放方式')}}</label>
  122. <t-radio-group class="ml-8" v-model="data.meta2dData.scaleMode" @change="changeValue($event, 'scaleMode')">
  123. <t-radio value="1" style="width: 200px" :title="$t('宽高中较小的铺满')">
  124. {{$t('自动铺满')}}
  125. </t-radio>
  126. <t-radio value="2" style="width: 200px" :title="$t('高度等比例缩放')">
  127. {{$t('宽度铺满')}}
  128. </t-radio>
  129. <t-radio value="3" :title="$t('宽度等比例缩放')">{{$t('高度铺满')}}</t-radio>
  130. </t-radio-group>
  131. </div>
  132. <div class="form-item">
  133. <label>{{$t('显示滚动条')}}</label>
  134. <t-checkbox v-model="data.meta2dData.scroll" @change="changeValue($event, 'scroll')" class="ml-8"></t-checkbox>
  135. </div>
  136. <div class="form-item">
  137. <label>{{$t('禁止移动')}}</label>
  138. <t-checkbox v-model="data.meta2dData.isDisableTranslate" @change="changeValue($event, 'isDisableTranslate')" class="ml-8"></t-checkbox>
  139. </div>
  140. <div class="form-item">
  141. <label>{{$t('禁止缩放')}}</label>
  142. <t-checkbox v-model="data.meta2dData.isDisableScale" @change="changeValue($event, 'isDisableScale')" class="ml-8"></t-checkbox>
  143. </div>
  144. <!-- <template v-if="data.scroll">
  145. <div class="form-item">
  146. <label>水平对齐</label>
  147. <t-radio-group class="ml-8" default-value="2">
  148. <t-radio value="1" style="width: 200px">左对齐</t-radio>
  149. <t-radio value="2" style="width: 200px">居中</t-radio>
  150. <t-radio value="3" style="width: 200px">右对齐</t-radio>
  151. </t-radio-group>
  152. </div>
  153. <div class="form-item">
  154. <label>垂直对齐</label>
  155. <t-radio-group class="ml-8" default-value="2">
  156. <t-radio value="1" style="width: 200px">顶部对齐</t-radio>
  157. <t-radio value="2" style="width: 200px">居中</t-radio>
  158. <t-radio value="3" style="width: 200px">底部对齐</t-radio>
  159. </t-radio-group>
  160. </div>
  161. </template> -->
  162. </t-space>
  163. </t-collapse-panel>
  164. <t-collapse-panel value="2" :header="$t('进阶设置')">
  165. <t-space direction="vertical" size="small">
  166. <div class="form-item">
  167. <label>
  168. {{$t('图标')}}URL
  169. <span>
  170. <!-- <label
  171. class="vip-label"
  172. style="font-size: 10px; padding: 0 2px"
  173. >
  174. VIP
  175. </label> -->
  176. </span>
  177. </label>
  178. <div class="px-8" style="width: 200px">
  179. <template v-if="data.meta2dData.iconUrls">
  180. <div
  181. v-for="(icon, i) of data.meta2dData.iconUrls"
  182. class="flex middle between"
  183. style="height: 30px"
  184. >
  185. <div>
  186. {{ icon.substring(0, 8) }}...{{ icon.substr(-16) }}
  187. </div>
  188. <close-icon class="hover"
  189. @click="removeIconUrl(i)"/>
  190. <!-- <t-icon
  191. name="close"
  192. class="hover"
  193. @click="removeIconUrl(i)"
  194. /> -->
  195. </div>
  196. </template>
  197. <div class="flex middle">
  198. <t-input v-model="data.iconUrl" style="width: 150px; margin-left: -8px" :placeholder="$t('Font class方式URL')"></t-input>
  199. <t-button variant="outline" style="padding: 4px 8px; margin-left: 8px" @click="addIconUrl">
  200. {{$t('添加')}}
  201. </t-button>
  202. </div>
  203. <!-- <div v-else class="desc mt-4">
  204. 支持添加iconfont。
  205. <a :href="(getEnterprise as any).account" target="_blank">VIP</a>
  206. 功能
  207. </div> -->
  208. </div>
  209. </div>
  210. <div class="form-item">
  211. <label>{{$t('初始化动作')}}</label>
  212. <t-button variant="outline" style="padding: 0 4px; margin: 2px 8px" @click="showInitFnDialog">
  213. <ellipsis-icon></ellipsis-icon>
  214. <!-- <t-icon name="ellipsis" /> -->
  215. </t-button>
  216. </div>
  217. <!-- <div class="form-item">
  218. <label>数据监听</label>
  219. <t-button
  220. variant="outline"
  221. style="padding: 0 4px; margin: 2px 8px"
  222. @click="showDataTransformation"
  223. >
  224. <ellipsis-icon />
  225. </t-button>
  226. </div> -->
  227. </t-space>
  228. </t-collapse-panel>
  229. <t-collapse-panel value="3" :header="$t('辅助设置')">
  230. <t-space direction="vertical" size="small">
  231. <div class="form-item">
  232. <label :title="$t('此功能仅对直线和折线有效')">{{$t('连线相交弯曲')}}</label>
  233. <t-switch :value="extendData.lineIntersect" class="ml-8 mt-8" size="small" @change="changeLineIntersect"></t-switch>
  234. </div>
  235. </t-space>
  236. <t-space direction="vertical" size="small">
  237. <div class="form-item">
  238. <label :title="$t('此功能仅对dxf文件解析结果')">{{$t('dxf缩放倍率')}}</label>
  239. <t-input
  240. class="ml-8"
  241. size="small"
  242. @change="refreshDxf"
  243. />
  244. </div>
  245. </t-space>
  246. </t-collapse-panel>
  247. </t-collapse>
  248. </t-space>
  249. </t-tab-panel>
  250. <t-tab-panel v-if="isShow" :value="3" :label="$t('行为')">
  251. <GlobalStates></GlobalStates>
  252. </t-tab-panel>
  253. <!-- <t-tab-panel :value="2" label="结构">
  254. <ElementTree />
  255. </t-tab-panel> -->
  256. </t-tabs>
  257. <t-dialog v-if="initFnDialog.show" :visible="true" @confirm="onOkInitFn" @close="initFnDialog.show = false" :width="700" :header="$t('初始化动作')">
  258. <CodeEditor v-model="initFnDialog.data" style="height: 300px"></CodeEditor>
  259. </t-dialog>
  260. <t-dialog v-if="dataTransformationDialog.show" :visible="true" @confirm="onOkDataTransformation" @close="dataTransformationDialog.show = false" :width="700" :header="$t('数据监听')">
  261. <CodeEditor v-model="dataTransformationDialog.data" style="height: 300px"></CodeEditor>
  262. </t-dialog>
  263. </div>
  264. </template>
  265. <script lang="ts" setup>
  266. import { onMounted, reactive, onUnmounted, getCurrentInstance } from 'vue';
  267. import axios from 'axios';
  268. import { useUser } from '@/services/user';
  269. // import { getCookie } from '@/services/cookie';
  270. // import ElementTree from './ElementTree.vue';
  271. import CodeEditor from '@/views/components/common/CodeEditor.vue';
  272. import { autoSave, inTreePanel, useAssets } from '@/services/common';
  273. import { MessagePlugin } from 'tdesign-vue-next';
  274. import { loadCss } from '@meta2d/core';
  275. import { defaultPureColor } from '@/services/defaults';
  276. import { useEnterprise } from '@/services/enterprise';
  277. import { MoreIcon, CloseIcon, EllipsisIcon} from 'tdesign-icons-vue-next';
  278. import { useMeta2dData,useExtendData } from '@/services/common';
  279. import { lineCross,clearLineCross,handleLineCross } from '@meta2d/utils';
  280. import GlobalStates from './GlobalStates.vue';
  281. import { getToken } from '@le5le/auth-token';
  282. import D2M from 'dxf';
  283. import { getImgUrl } from '@/services/utils';
  284. import { useModuleType } from '@/services/module-type';
  285. const { getEnterprise } = useEnterprise();
  286. const { meta2dData, setMeta2dData } = useMeta2dData();
  287. const { extendData, setExtendData } = useExtendData();
  288. const { proxy } = getCurrentInstance();
  289. const $t = proxy.$t
  290. const headers = {
  291. // Authorization: 'Bearer ' + (getToken() || ''),
  292. Authorization: 'Bearer ' + import.meta.env.VITE_TEMP_TOKEN,
  293. };
  294. const updataData = { directory: '/大屏/图片/默认' };
  295. // const { assets } = useAssets();
  296. const { user } = useUser();
  297. const { isBigScreen } = useModuleType();
  298. const isShow = globalThis.globalStates;
  299. const data = reactive<any>({
  300. tab: 1,
  301. background: [],
  302. meta2dData: {},
  303. iconUrl: '',
  304. });
  305. const cases = [
  306. {
  307. label:$t('智慧物联'),
  308. value:$t('智慧物联')
  309. },
  310. {
  311. label:$t('电力能源'),
  312. value:$t('电力能源')
  313. },
  314. {
  315. label:$t('智慧水务'),
  316. value:$t('智慧水务')
  317. },
  318. {
  319. label:$t('智慧工厂'),
  320. value:$t('智慧工厂')
  321. },
  322. {
  323. label:$t('智慧校园'),
  324. value:$t('智慧校园')
  325. },
  326. {
  327. label:$t('智慧园区'),
  328. value:$t('智慧园区')
  329. },
  330. {
  331. label:$t('智慧交通'),
  332. value:$t('智慧交通')
  333. },
  334. {
  335. label:$t('智慧城市'),
  336. value:$t('智慧城市')
  337. },
  338. {
  339. label:$t('智慧农业'),
  340. value:$t('智慧农业')
  341. },
  342. {
  343. label:$t('电信机房'),
  344. value:$t('电信机房')
  345. },
  346. {
  347. label:$t('航空航天'),
  348. value:$t('航空航天')
  349. },
  350. {
  351. label:$t('智能家居'),
  352. value:$t('智能家居')
  353. }
  354. ];
  355. const themeOptions = [
  356. {
  357. label: $t('暗黑'),
  358. value: 'dark',
  359. },
  360. {
  361. label: $t('明亮'),
  362. value: 'light',
  363. },
  364. ];
  365. const screenList = reactive([
  366. {
  367. name: $t('大屏'),
  368. width: 1920,
  369. height: 1080,
  370. },
  371. {
  372. name: $t('网页'),
  373. width: 1440,
  374. height: 1024,
  375. },
  376. {
  377. name: '平板12.9"',
  378. width: 1024,
  379. height: 1366,
  380. },
  381. {
  382. name: '平板11"',
  383. width: 834,
  384. height: 1194,
  385. },
  386. {
  387. name: $t('平板Mini'),
  388. width: 768,
  389. height: 1024,
  390. },
  391. {
  392. name: $t('华为P8'),
  393. width: 360,
  394. height: 640,
  395. },
  396. {
  397. name: $t('华为P40'),
  398. width: 395,
  399. height: 856,
  400. },
  401. {
  402. name: $t('手机1'),
  403. width: 430,
  404. height: 932,
  405. },
  406. {
  407. name: $t('手机2'),
  408. width: 375,
  409. height: 812,
  410. },
  411. ]);
  412. const initFnDialog = reactive<any>({
  413. show: false,
  414. data: '',
  415. });
  416. const dataTransformationDialog = reactive<any>({
  417. show: false,
  418. data: '',
  419. });
  420. const selectedSreen = (item: any) => {
  421. meta2d.store.data.width = item.width;
  422. meta2d.store.data.height = item.height;
  423. // meta2d.store.patchFlagsBackground = true;
  424. meta2d.canvas.canvasTemplate.bgPatchFlags = true;
  425. meta2d.render();
  426. openData();
  427. };
  428. const beforeUpload = (file: any) => {
  429. // if (!(user && user.id)) {
  430. // MessagePlugin.warning($t('请先登录!'));
  431. // return false;
  432. // }
  433. return true;
  434. };
  435. const fileSuccessed = async (content: any) => {
  436. // meta2d.store.patchFlagsBackground = true;
  437. meta2d.setBackgroundImage(getImgUrl(content.response.data?.url));
  438. setTimeout(() => {
  439. // meta2d.store.patchFlagsBackground = true;
  440. meta2d.render();
  441. }, 1000);
  442. };
  443. const fileRemoved = () => {
  444. meta2d.setBackgroundImage('');
  445. // meta2d.store.patchFlagsBackground = true;
  446. meta2d.render();
  447. data.background = [];
  448. };
  449. const changeLineIntersect = (e:any)=>{
  450. setExtendData('lineIntersect',e);
  451. if(e){
  452. lineCross(false);
  453. // handleLineCross(meta2d.store.active.length>0);
  454. }else{
  455. clearLineCross();
  456. }
  457. }
  458. const changeValue = (e: any, key: string) => {
  459. // @ts-ignore
  460. meta2d.store.data[key] = e;
  461. if (key === 'background') {
  462. // meta2d.store.patchFlagsBackground = true;
  463. meta2d.setBackgroundColor(e);
  464. } else if (key === 'width' || key === 'height') {
  465. meta2d.canvas.canvasTemplate.bgPatchFlags = true;
  466. }
  467. meta2d.render();
  468. openData();
  469. };
  470. const changeGrid = (e: any, key: string)=>{
  471. let opt = {[key]: e}
  472. if(key === 'gridSize') {
  473. if(e <= 5) return;
  474. }
  475. if(key==='grid'&&e===true){
  476. opt.gridColor = '#303746';
  477. data.gridColor = '#303746';
  478. }
  479. meta2d.setOptions(opt);
  480. meta2d.render();
  481. }
  482. const changeTheme = (e)=>{
  483. meta2d.setTheme(e);
  484. data.meta2dData.background = meta2d.store.data.background;
  485. }
  486. const changeName = (e: any, key: string) => {
  487. setMeta2dData({name:e});
  488. };
  489. onMounted(() => {
  490. if (inTreePanel.value) {
  491. // data.tab = 2;
  492. }
  493. openData();
  494. meta2d.on('opened', openData);
  495. meta2d.on('add', finishLine);
  496. if(extendData.lineIntersect){
  497. lineCross(true);
  498. }
  499. });
  500. async function refreshDxf(scale:number){
  501. meta2d.clear()
  502. // 然后这将显示一个文本文件
  503. const parser = new D2M()
  504. parser.parser.configs.scale = scale
  505. const res = parser.reload()
  506. if(res.success.length > 0 ){
  507. const pens = await meta2d.addPens((res.success));
  508. meta2d.gotoView(pens[Math.floor(pens.length / 2)])
  509. // meta2d.gotoView(viewPen)
  510. // Promise.resolve().then(()=>{meta2d.render()})
  511. }
  512. }
  513. onUnmounted(() => {
  514. meta2d.off('opened', openData);
  515. meta2d.off('add', finishLine);
  516. setTimeout(()=>{
  517. clearLineCross();
  518. },2000);
  519. });
  520. function openData() {
  521. if (!(meta2d.store.data as any).scaleMode) {
  522. (meta2d.store.data as any).scaleMode = '1';
  523. }
  524. data.meta2dData = Object.assign({}, meta2d.store.data);
  525. if (meta2d.store.data.bkImage) {
  526. data.background = [
  527. {
  528. name: meta2d.store.data.bkImage,
  529. url: meta2d.store.data.bkImage,
  530. },
  531. ];
  532. }
  533. if(meta2d?.store?.options?.grid){
  534. data.grid = meta2d.store.options.grid;
  535. data.gridSize = meta2d.store.options?.gridSize;
  536. data.gridColor = meta2d.store.options?.gridColor;
  537. data.autoAlignGrid = meta2d.store.options?.autoAlignGrid;
  538. }
  539. }
  540. function finishLine(e) {
  541. setTimeout(()=>{
  542. if(e[0].type === 1 && e[0].name === 'line' && ['line',"polyline"].indexOf(e[0].lineName) !== -1){
  543. extendData.lineIntersect && handleLineCross(meta2d.store.active.length>0);
  544. }
  545. },500)
  546. }
  547. const showInitFnDialog = () => {
  548. initFnDialog.data = meta2d.store.data.initJs;
  549. initFnDialog.show = true;
  550. };
  551. const onOkInitFn = () => {
  552. meta2d.store.data.initJs = initFnDialog.data;
  553. initFnDialog.show = false;
  554. };
  555. const showDataTransformation = () => {
  556. dataTransformationDialog.data = meta2d.store.data.socketCbJs;
  557. dataTransformationDialog.show = true;
  558. };
  559. const onOkDataTransformation = () => {
  560. meta2d.store.data.socketCbJs = dataTransformationDialog.data;
  561. meta2d.listenSocket();
  562. dataTransformationDialog.show = false;
  563. };
  564. const addIconUrl = () => {
  565. if (!data.iconUrl || data.iconUrl.substr(-4) !== '.css') {
  566. MessagePlugin.error($t('请填写以.css结尾的font-class引用方式的URL地址'));
  567. return;
  568. }
  569. if (!data.meta2dData.iconUrls) {
  570. data.meta2dData.iconUrls = [];
  571. }
  572. data.meta2dData.iconUrls.push(data.iconUrl);
  573. // @ts-ignore
  574. meta2d.store.data.iconUrls = data.meta2dData.iconUrls;
  575. if (meta2d.store.data.iconUrls) {
  576. for (const item of meta2d.store.data.iconUrls) {
  577. loadCss(item);
  578. }
  579. }
  580. data.iconUrl = '';
  581. autoSave(true);
  582. };
  583. const removeIconUrl = (i: number) => {
  584. data.meta2dData.iconUrls.splice(i, 1);
  585. // @ts-ignore
  586. meta2d.store.data.iconUrls = data.meta2dData.iconUrls;
  587. autoSave(true);
  588. };
  589. </script>
  590. <style lang="postcss" scoped>
  591. .props {
  592. }
  593. </style>