View.vue 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534
  1. <template>
  2. <div class="meta2d">
  3. <div class="tools">
  4. <t-tooltip content="新建" placement="bottom">
  5. <a><t-icon name="add" @click="newFile" /></a>
  6. </t-tooltip>
  7. <t-tooltip content="保存为大屏" placement="bottom">
  8. <a>
  9. <t-badge
  10. :class="{ gray: route.query.c }"
  11. dot
  12. :showZero="false"
  13. :count="dot ? 1 : 0"
  14. >
  15. <t-icon
  16. name="save"
  17. @click="!route.query.c && save(SaveType.Save, false, true)"
  18. />
  19. </t-badge>
  20. </a>
  21. </t-tooltip>
  22. <t-tooltip content="保存为我的组件" placement="bottom">
  23. <a :class="{ gray: route.query.id && !route.query.c }">
  24. <t-icon
  25. name="layers"
  26. @click="
  27. (!route.query.id || route.query.c) &&
  28. save(SaveType.Save, true, true)
  29. "
  30. />
  31. </a>
  32. </t-tooltip>
  33. <t-tooltip content="格式化(双击可连续使用)" placement="bottom">
  34. <a
  35. @click="oneFormat"
  36. @dblclick="alwaysFormat"
  37. :style="{
  38. color: one || always ? ' #1677ff' : '',
  39. }"
  40. >
  41. <svg
  42. width="1em"
  43. height="1em"
  44. viewBox="0 0 256 256"
  45. xmlns="http://www.w3.org/2000/svg"
  46. xmlns:xlink="http://www.w3.org/1999/xlink"
  47. >
  48. <defs>
  49. <path id="77456364" d="M0 0h256v256H0z"></path>
  50. </defs>
  51. <g fill="none" fill-rule="evenodd">
  52. <mask id="3804093554b" fill="#fff">
  53. <use xlink:href="#77456364"></use>
  54. </mask>
  55. <path
  56. d="M213 77c0 14.36-11.64 26-26 26H69c-14.36 0-26-11.64-26-26V51c0-14.36 11.64-26 26-26h118c14.36 0 26 11.64 26 26v2h9.125c9.83 0 17.82 7.88 17.997 17.67l.003.33v50c0 9.83-7.88 17.82-17.67 17.997l-.33.003h-84.626v18H139c9.83 0 17.82 7.88 17.997 17.67l.003.33v35c0 16.016-12.984 29-29 29-15.856 0-28.74-12.725-28.996-28.52L99 210v-35c0-9.83 7.88-17.82 17.67-17.997L117 157h.499l.001-20c0-9.83 7.88-17.82 17.67-17.997l.33-.003h84.625V73H213Zm-76 100h-18v33a9 9 0 0 0 8.471 8.985l.264.011.265.004a9 9 0 0 0 8.996-8.735L137 210v-33Zm50-132H69a6 6 0 0 0-6 6v26a6 6 0 0 0 6 6h118a6 6 0 0 0 6-6V51a6 6 0 0 0-6-6Z"
  57. fill="currentColor"
  58. fill-rule="nonzero"
  59. mask="url(#3804093554b)"
  60. ></path>
  61. </g>
  62. </svg>
  63. </a>
  64. </t-tooltip>
  65. <t-tooltip content="清除格式" placement="bottom">
  66. <a @click="clearFormat">
  67. <svg
  68. width="1em"
  69. height="1em"
  70. viewBox="0 0 1024 1024"
  71. xmlns="http://www.w3.org/2000/svg"
  72. >
  73. <path
  74. d="M889.186 384.07 677.671 172.56c-53.063-53.063-139.094-53.063-192.157 0L134.617 523.457c-53.063 53.063-53.063 139.099 0 192.158l170.196 170.2a41.354 41.354 0 0 0 29.243 12.11h215.001a41.354 41.354 0 0 0 29.184-12.05L889.155 576.26c53.094-53.09 53.094-139.126.031-192.19zM830.7 442.558c20.48 20.472 20.764 53.492.855 74.319l-.961.984-298.618 297.358H351.185l-158.09-158.086c-20.76-20.763-20.76-54.43 0-75.193l350.901-350.897c20.764-20.764 54.43-20.764 75.193 0l211.515 211.511z"
  75. fill="currentColor"
  76. ></path>
  77. <path
  78. d="m685.505 678.754-58.19 58.77-317.587-314.43 58.191-58.774zm197.55 136.508c23.46 0 42.483 18.514 42.483 41.353 0 22.45-18.38 40.724-41.294 41.338l-1.19.016h-454.6c-23.462 0-42.485-18.514-42.485-41.354 0-22.449 18.381-40.723 41.295-41.338l1.19-.015h454.6z"
  79. fill="currentColor"
  80. ></path>
  81. </svg>
  82. </a>
  83. </t-tooltip>
  84. <div class="flex-grow"></div>
  85. <t-tooltip content="直线" placement="bottom">
  86. <a
  87. :draggable="true"
  88. @dragstart="onAddShape($event, 'line')"
  89. @click.stop="onAddShape($event, 'line')"
  90. ><t-icon name="slash"
  91. /></a>
  92. </t-tooltip>
  93. <t-tooltip content="文字" placement="bottom">
  94. <a
  95. :draggable="true"
  96. @dragstart="onAddShape($event, 'text')"
  97. @click.stop="onAddShape($event, 'text')"
  98. >T</a
  99. >
  100. </t-tooltip>
  101. <t-tooltip content="连线(双击可连续使用)" placement="bottom">
  102. <a
  103. @click="oneDraw"
  104. @dblclick="alwaysDraw"
  105. :style="{
  106. color: oneD || alwaysD ? ' #1677ff' : '',
  107. }"
  108. >
  109. <svg
  110. width="1em"
  111. height="1em"
  112. viewBox="0 0 1024 1024"
  113. xmlns="http://www.w3.org/2000/svg"
  114. >
  115. <path
  116. d="M192 64a128 128 0 0 1 123.968 96H384a160 160 0 0 1 159.68 149.504L544 320v384a96 96 0 0 0 86.784 95.552L640 800h68.032a128 128 0 1 1 0 64.064L640 864a160 160 0 0 1-159.68-149.504L480 704V320a96 96 0 0 0-86.784-95.552L384 224l-68.032 0.064A128 128 0 1 1 192 64z m640 704a64 64 0 1 0 0 128 64 64 0 0 0 0-128zM192 128a64 64 0 1 0 0 128 64 64 0 0 0 0-128z"
  117. fill="currentColor"
  118. ></path>
  119. </svg>
  120. </a>
  121. </t-tooltip>
  122. <t-dropdown
  123. :minColumnWidth="200"
  124. :maxHeight="560"
  125. :delay2="[10, 150]"
  126. overlayClassName="header-dropdown"
  127. >
  128. <a>
  129. <svg class="l-icon" aria-hidden="true">
  130. <use
  131. :xlink:href="
  132. lineTypes.find((item) => item.value === currentLineType)?.icon
  133. "
  134. ></use>
  135. </svg>
  136. </a>
  137. <t-dropdown-menu>
  138. <t-dropdown-item v-for="item in lineTypes">
  139. <div class="flex middle" @click="changeLineType(item.value)">
  140. {{ item.name }} <span class="flex-grow"></span>
  141. <svg class="l-icon" aria-hidden="true">
  142. <use :xlink:href="item.icon"></use>
  143. </svg>
  144. </div>
  145. </t-dropdown-item>
  146. </t-dropdown-menu>
  147. </t-dropdown>
  148. <t-dropdown
  149. :minColumnWidth="200"
  150. :maxHeight="560"
  151. :delay2="[10, 150]"
  152. overlayClassName="header-dropdown"
  153. >
  154. <a>
  155. <svg class="l-icon" aria-hidden="true">
  156. <use
  157. :xlink:href="
  158. fromArrows.find((item) => item.value === fromArrow)?.icon
  159. "
  160. ></use>
  161. </svg>
  162. </a>
  163. <t-dropdown-menu>
  164. <t-dropdown-item v-for="item in fromArrows">
  165. <div
  166. class="flex middle"
  167. style="height: 30px"
  168. @click="changeFromArrow(item.value)"
  169. >
  170. <svg class="l-icon" aria-hidden="true">
  171. <use :xlink:href="item.icon"></use>
  172. </svg>
  173. </div>
  174. </t-dropdown-item>
  175. </t-dropdown-menu>
  176. </t-dropdown>
  177. <t-dropdown
  178. :minColumnWidth="200"
  179. :maxHeight="560"
  180. :delay2="[10, 150]"
  181. overlayClassName="header-dropdown"
  182. >
  183. <a>
  184. <svg class="l-icon" aria-hidden="true">
  185. <use
  186. :xlink:href="
  187. toArrows.find((item) => item.value === toArrow)?.icon
  188. "
  189. ></use>
  190. </svg>
  191. </a>
  192. <t-dropdown-menu>
  193. <t-dropdown-item v-for="item in toArrows">
  194. <div
  195. class="flex middle"
  196. style="height: 30px"
  197. @click="changeToArrow(item.value)"
  198. >
  199. <svg class="l-icon" aria-hidden="true">
  200. <use :xlink:href="item.icon"></use>
  201. </svg>
  202. </div>
  203. </t-dropdown-item>
  204. </t-dropdown-menu>
  205. </t-dropdown>
  206. <!-- </t-tooltip> -->
  207. <t-tooltip content="视图大小" placement="bottom">
  208. <div style="line-height: 40px; margin-left: 8px">{{ scale }}%</div>
  209. </t-tooltip>
  210. <t-tooltip content="100%视图" placement="bottom">
  211. <a @click="onScaleView"><t-icon name="refresh" /></a>
  212. </t-tooltip>
  213. <t-tooltip content="窗口大小" placement="bottom">
  214. <a @click="onScaleWindow"><t-icon name="fullscreen-exit" /></a>
  215. </t-tooltip>
  216. <t-tooltip content="数据源" placement="bottom">
  217. <a @click="onShowDataDialog"><t-icon name="server" /></a>
  218. </t-tooltip>
  219. <div class="flex-grow"></div>
  220. <t-tooltip :content="isLock ? '浏览模式' : '编辑模式'" placement="bottom">
  221. <a>
  222. <svg
  223. v-if="isLock"
  224. class="l-icon"
  225. aria-hidden="true"
  226. @click="onLock(0)"
  227. >
  228. <use xlink:href="#l-lock"></use>
  229. </svg>
  230. <svg v-else class="l-icon" aria-hidden="true" @click="onLock(1)">
  231. <use xlink:href="#l-unlock"></use>
  232. </svg>
  233. </a>
  234. </t-tooltip>
  235. <t-tooltip content="运行(查看)" placement="bottom">
  236. <a @click="preview"><t-icon name="caret-right" /></a>
  237. </t-tooltip>
  238. <t-tooltip content="分享" placement="bottom">
  239. <a @click="share">
  240. <t-icon name="share" :class="{ primary: shared }" />
  241. </a>
  242. </t-tooltip>
  243. <t-popup placement="bottom" v-model="qrcode.visible">
  244. <a><t-icon name="qrcode" /></a>
  245. <template #content>
  246. <div style="padding: 12px 12px 6px 12px">
  247. <img v-if="route.query.id && !route.query.c" :src="qrcode.url" />
  248. <div
  249. v-else-if="!route.query.id"
  250. class="gray center mb-4"
  251. style="font-size: 10px; margin-bottom: 6px"
  252. >
  253. 当前项目为本地编辑模式<br />
  254. 请保存为大屏项目后访问
  255. </div>
  256. <div
  257. v-else
  258. class="gray center mb-4"
  259. style="font-size: 10px; margin-bottom: 6px"
  260. >
  261. 仅支持手机访问大屏项目
  262. </div>
  263. </div>
  264. </template>
  265. </t-popup>
  266. <t-tooltip content="云发布" placement="bottom">
  267. <a @click="onShowPublish"><t-icon name="cloud" /></a>
  268. </t-tooltip>
  269. </div>
  270. <div id="meta2d"></div>
  271. <ContextMenu
  272. v-if="contextmenu.visible"
  273. :type="contextmenu.type"
  274. :style="contextmenu.style"
  275. @changeVisible="changeContextMenuVisible"
  276. />
  277. <t-dialog
  278. v-if="dataDialog.show"
  279. width="800px"
  280. header="数据源管理"
  281. :visible="true"
  282. @close="dataDialog.show = false"
  283. >
  284. <t-tabs :default-value="1" class="body">
  285. <t-tab-panel :value="1" label="数据订阅" :destroy-on-hide="false">
  286. <template #panel>
  287. <div v-if="!dataDialog.editNetwork">
  288. <t-row class="mt-16" justify="end">
  289. <t-space :size="12">
  290. <t-select-input
  291. placeholder="搜索我的数据源"
  292. allow-input
  293. clearable
  294. :popup-visible="dataDialog.popupVisible"
  295. @input-change="onInputNetwork"
  296. style="width: 240px"
  297. >
  298. <template #panel>
  299. <ul style="padding: 4px">
  300. <li
  301. class="hover-background"
  302. style="
  303. line-height: 1.5;
  304. padding: 8px;
  305. border-radius: 2px;
  306. "
  307. v-for="item in dataDialog.networkList"
  308. :key="item.url"
  309. @click="() => onSelectNetWork(item)"
  310. >
  311. 名称: {{ item.name }}
  312. <div class="desc">地址: {{ item.url }}</div>
  313. </li>
  314. <li
  315. v-if="!dataDialog.networkList.length"
  316. style="
  317. line-height: 1.5;
  318. padding: 8px;
  319. border-radius: 2px;
  320. "
  321. :key="-1"
  322. >
  323. <div class="desc">暂无数据</div>
  324. </li>
  325. </ul>
  326. </template>
  327. <template #suffixIcon>
  328. <t-icon name="search" class="hover" />
  329. </template>
  330. </t-select-input>
  331. <t-button style="height: 30px" @click="addNetwork">
  332. 添加数据订阅
  333. </t-button>
  334. </t-space>
  335. </t-row>
  336. <t-table
  337. class="mt-12"
  338. row-key="id"
  339. :data="dataDialog.networks"
  340. :columns="networkColumns"
  341. :max-height="280"
  342. size="small"
  343. >
  344. <template #actions="{ row, rowIndex }">
  345. <a @click="editNetwork(row)"> 编辑 </a>
  346. <t-popconfirm
  347. content="确认删除吗"
  348. @confirm="deleteNetwork(rowIndex)"
  349. >
  350. <a class="ml-12"> 删除 </a>
  351. </t-popconfirm>
  352. </template>
  353. <template #empty>
  354. <div class="center">
  355. <div>暂无数据</div>
  356. <div class="mt-8">
  357. <a @click="addNetwork"> + 添加数据订阅</a>
  358. </div>
  359. </div>
  360. </template>
  361. </t-table>
  362. </div>
  363. <div v-else>
  364. <div class="mt-8">
  365. <a
  366. @click="dataDialog.editNetwork = false"
  367. class="flex middle"
  368. style="width: 44px"
  369. >
  370. <t-icon name="rollback" class="mr-4" /> 返回
  371. </a>
  372. </div>
  373. <div style="height: 300px; overflow-y: auto">
  374. <Network v-model="dataDialog.network" />
  375. </div>
  376. </div>
  377. </template>
  378. </t-tab-panel>
  379. <t-tab-panel :value="2" :destroy-on-hide="false">
  380. <template #label>
  381. 数据集
  382. <span><label class="vip-label ml-4">VIP</label></span>
  383. </template>
  384. <template #panel>
  385. <div class="form-item mt-20">
  386. <label style="width: 100px">
  387. 网络地址
  388. <t-tooltip
  389. content="使用网络数据代替自定义数据。高优先级,生产环境使用"
  390. >
  391. <t-icon
  392. name="help-circle"
  393. class="ml-4 hover"
  394. style="margin-top: -2px"
  395. />
  396. </t-tooltip>
  397. </label>
  398. <div class="w-full">
  399. <t-input v-model="dataDialog.datasetUrl" />
  400. </div>
  401. </div>
  402. <div class="form-item" style="margin-top: 28px">
  403. <label style="width: 100px">
  404. 自定义
  405. <t-tooltip content="初始静态或模拟数据,开发设计阶段使用">
  406. <t-icon
  407. name="help-circle"
  408. class="ml-4 hover"
  409. style="margin-top: -2px"
  410. />
  411. </t-tooltip>
  412. </label>
  413. <div class="w-full flex">
  414. <t-button @click="importDataset">从Excel导入</t-button>
  415. <a href="/data.xlsx" download class="ml-16 mt-4">
  416. 下载Excel示例
  417. </a>
  418. <div class="flex-grow"></div>
  419. <a class="mt-4" @click="showAddData()"> + 添加数据 </a>
  420. </div>
  421. </div>
  422. <t-table
  423. class="mt-12"
  424. row-key="id"
  425. :data="dataDialog.dataset"
  426. :columns="datasetColumns"
  427. size="small"
  428. :max-height="210"
  429. >
  430. <template #label="{ row }">
  431. {{ `${row.label}(${row.key})` }}
  432. </template>
  433. <template #type="{ row }">
  434. {{ row.type || 'string' }}
  435. </template>
  436. <template #actions="{ row, rowIndex }">
  437. <t-icon name="edit" class="hover" @click="showAddData(row)" />
  438. <t-icon
  439. name="delete"
  440. class="ml-12 hover"
  441. @click="dataDialog.dataset.splice(rowIndex, 1)"
  442. />
  443. </template>
  444. <template #empty>
  445. <div class="center">
  446. 暂无数据, <a class="mt-4" @click="showAddData()"> + 添加 </a>
  447. </div>
  448. </template>
  449. </t-table>
  450. </template>
  451. </t-tab-panel>
  452. </t-tabs>
  453. <template #footer>
  454. <div v-if="dataDialog.editNetwork" class="flex middle">
  455. <div class="flex-grow"></div>
  456. <t-checkbox v-model="dataDialog.save">
  457. 同时保存到我的数据源
  458. </t-checkbox>
  459. <t-button class="ml-16" @click="onOkNetwork">确定</t-button>
  460. </div>
  461. <div v-else class="flex middle">
  462. <div class="flex-grow"></div>
  463. <t-button class="ml-16" @click="dataDialog.show = false">
  464. 完成
  465. </t-button>
  466. </div>
  467. </template>
  468. </t-dialog>
  469. <t-dialog
  470. v-if="addDataDialog.show"
  471. :visible="true"
  472. class="data-dialog"
  473. :header="addDataDialog.header"
  474. @close="addDataDialog.show = false"
  475. @confirm="onOkAddData"
  476. >
  477. <div class="form-item mt-16">
  478. <label>名称</label>
  479. <t-input v-model="addDataDialog.data.label" placeholder="简短描述" />
  480. </div>
  481. <div class="form-item mt-16">
  482. <label>数据ID</label>
  483. <t-input v-model="addDataDialog.data.key" placeholder="数据ID" />
  484. </div>
  485. <div class="form-item mt-16">
  486. <label>类型</label>
  487. <t-select
  488. class="w-full"
  489. :options="typeOptions"
  490. v-model="addDataDialog.data.type"
  491. placeholder="字符串"
  492. @change="addDataDialog.data.value = null"
  493. />
  494. </div>
  495. <div class="form-item mt-16">
  496. <label>值</label>
  497. <div class="flex-grow" v-if="addDataDialog.data.type === 'number'">
  498. <t-input
  499. class="w-full"
  500. v-model="addDataDialog.data.value"
  501. placeholder="数字"
  502. />
  503. <div class="desc mt-8">
  504. 固定数字:直接输入数字。例如:5<br />
  505. 随机范围数字 :最小值-最大值。例如:0-1 或 0-100
  506. <br />
  507. 随机指定数字 :数字1,数字2,数字3... 。 例如:1,5,10,20<br />
  508. </div>
  509. </div>
  510. <div class="flex-grow" v-else-if="addDataDialog.data.type === 'bool'">
  511. <t-select v-model="addDataDialog.data.value">
  512. <t-option :key="true" :value="true" label="true"></t-option>
  513. <t-option :key="false" :value="false" label="false"></t-option>
  514. <t-option key="随机" label="随机"></t-option>
  515. </t-select>
  516. <div class="desc mt-8">
  517. 固定:指定true或false<br />
  518. 随机:随机生成一个布尔值<br />
  519. </div>
  520. </div>
  521. <div
  522. class="flex-grow"
  523. v-else-if="
  524. addDataDialog.data.type === 'array' ||
  525. addDataDialog.data.type === 'object'
  526. "
  527. >
  528. <CodeEditor v-model="addDataDialog.data.value" :json="true" />
  529. </div>
  530. <div class="flex-grow" v-else>
  531. <t-input
  532. class="w-full"
  533. v-model="addDataDialog.data.value"
  534. placeholder="字符串"
  535. />
  536. <div class="desc mt-8">
  537. 固定文字:直接输入。例如:大屏可视化<br />
  538. 随机文本:[文本长度]。例如:[8] 或 [16]<br />
  539. 随机指定文本:{文本1,文本2,文本3...} 。 例如:{大屏, 可视化}
  540. <br />
  541. </div>
  542. </div>
  543. </div>
  544. </t-dialog>
  545. <t-dialog
  546. v-if="publishDialog.show"
  547. width="700px"
  548. header="云发布"
  549. :visible="true"
  550. :cancel-btn="null"
  551. :confirm-btn="'完成'"
  552. @close="publishDialog.show = false"
  553. >
  554. <div class="body" style="height: 350px">
  555. <div class="form-item mt-8">
  556. <label>项目名称</label>
  557. <div class="flex middle">
  558. <t-icon name="laptop" class="mr-8" /> {{ publishDialog.name }}
  559. </div>
  560. </div>
  561. <template v-if="publishDialog.data">
  562. <div class="form-item mt-8">
  563. <label>发布状态</label>
  564. <div v-if="publishDialog.data.id" class="flex middle">
  565. <div v-if="publishDialog.data.isExpired" class="warning">
  566. <t-icon name="stop-circle-1" class="mr-4" />
  567. 已过期
  568. </div>
  569. <div v-else class="primary">
  570. <t-icon name="play-circle" class="mr-4" />
  571. 正在运行
  572. </div>
  573. <div class="gray" style="margin-left: 32px; margin-top: -2px">
  574. 有效期至:{{ publishDialog.data.expired }}
  575. </div>
  576. <a class="bland ml-12" @click="publishChargeDialog.show = true">
  577. 续费
  578. </a>
  579. </div>
  580. <div v-else class="flex middle">
  581. <t-icon name="play-circle-stroke" class="mr-4" />
  582. 未发布
  583. </div>
  584. </div>
  585. <div class="form-item mt-16">
  586. <label>乐吾乐域名</label>
  587. <div class="flex w-full">
  588. <t-input
  589. v-model="publishDialog.data.subDomain"
  590. :maxlength="16"
  591. :status="publishDialog.status"
  592. :tips="publishDialog.tips"
  593. class="mr-4"
  594. style="width: 350px"
  595. placeholder="子域名"
  596. @change="onChangeSubdomain"
  597. />
  598. <t-tooltip content="随机生成">
  599. <t-icon
  600. name="refresh"
  601. class="hover"
  602. @click="refreshSubdomain"
  603. />
  604. </t-tooltip>
  605. <div class="mt-4 ml-16">v.le5le.com</div>
  606. </div>
  607. </div>
  608. <div class="form-item mt-24">
  609. <label>访问域名</label>
  610. <div class="w-full">
  611. <div class="flex middle">
  612. <t-input
  613. v-model="publishDialog.data.domain"
  614. style="width: 350px"
  615. placeholder="支持自定义域名"
  616. />
  617. <template v-if="publishDialog.data.domain">
  618. <a
  619. :href="`http://${publishDialog.data.domain}`"
  620. target="_blank"
  621. class="hover"
  622. style="margin-left: 36px; text-decoration: underline"
  623. >
  624. 点击访问
  625. </a>
  626. <t-popup
  627. placement="bottom"
  628. v-model="publishDialog.qrcodeVisible"
  629. >
  630. <a class="hover" style="margin-left: 32px">
  631. <t-icon name="qrcode" />
  632. <span
  633. style="margin-left: 2px; position: relative; top: 1px"
  634. >
  635. 手机访问
  636. </span>
  637. </a>
  638. <template #content>
  639. <div style="padding: 12px 12px 6px 12px">
  640. <img :src="publishDialog.url" />
  641. </div>
  642. </template>
  643. </t-popup>
  644. </template>
  645. </div>
  646. <div class="desc mt-12">
  647. <div class="title desc">- 注意</div>
  648. <div>仅支持48小时免费试用,到期后需要续费使用。</div>
  649. </div>
  650. <div class="desc mt-8">
  651. <div class="title desc">- 自定义域名</div>
  652. <div>
  653. 在域名服务商的DNS控制台设置好对应的CNAME,值为乐吾乐域名。
  654. <a
  655. href="https://doc.le5le.com/document/126505408"
  656. target="_blank"
  657. >
  658. 更多帮助
  659. </a>
  660. </div>
  661. </div>
  662. </div>
  663. </div>
  664. <div class="form-item mt-16">
  665. <label></label>
  666. <div class="w-full">
  667. <t-button @click="onPublish">发布</t-button>
  668. </div>
  669. </div>
  670. </template>
  671. <div v-else class="flex center" style="margin-top: 32px">
  672. <t-loading text="加载中..." size="small"></t-loading>
  673. </div>
  674. </div>
  675. </t-dialog>
  676. <t-dialog
  677. v-if="publishChargeDialog.show"
  678. v-model:visible="publishChargeDialog.show"
  679. header="云发布续费"
  680. :close-on-overlay-click="false"
  681. :width="700"
  682. :footer="false"
  683. >
  684. <ChargeCloudPublish
  685. :projectId="publishDialog.id"
  686. @success="onSuccessChargeCloud"
  687. />
  688. </t-dialog>
  689. </div>
  690. </template>
  691. <script lang="ts" setup>
  692. import { onMounted, onUnmounted, watch, ref, reactive } from 'vue';
  693. import { useRouter, useRoute } from 'vue-router';
  694. import {
  695. Meta2d,
  696. Options,
  697. Pen,
  698. deepClone,
  699. PenType,
  700. HoverType,
  701. } from '@meta2d/core';
  702. import localforage from 'localforage';
  703. import dayjs from 'dayjs';
  704. import QRCode from 'qrcode';
  705. import axios from 'axios';
  706. import { MessagePlugin } from 'tdesign-vue-next';
  707. import { registerBasicDiagram } from '@/services/register';
  708. import { useUser } from '@/services/user';
  709. import {
  710. cdn,
  711. getComponents,
  712. getLe5leV,
  713. updateCollection,
  714. } from '@/services/api';
  715. import {
  716. save,
  717. autoSave,
  718. newFile,
  719. SaveType,
  720. onScaleView,
  721. onScaleWindow,
  722. useDot,
  723. typeOptions,
  724. } from '@/services/common';
  725. import { useSelection } from '@/services/selections';
  726. import { defaultFormat } from '@/services/defaults';
  727. import { checkData, localStorageName, Meta2dBackData } from '@/services/utils';
  728. import { debounce } from '@/services/debouce';
  729. import { importExcel } from '@/services/excel';
  730. import { s8 } from '@/services/random';
  731. import CodeEditor from './common/CodeEditor.vue';
  732. import ContextMenu from './ContextMenu.vue';
  733. import Network from './Network.vue';
  734. import ChargeCloudPublish from './ChargeCloudPublish.vue';
  735. const router = useRouter();
  736. const route = useRoute();
  737. const { user } = useUser();
  738. const { dot, setDot } = useDot();
  739. const { select } = useSelection();
  740. const meta2dOptions: Options = {
  741. cdn,
  742. rule: true,
  743. background: '#1e2430',
  744. x: 32,
  745. y: 32,
  746. width: 1920,
  747. height: 1080,
  748. color: '#bdc7db',
  749. disableAnchor: true,
  750. defaultFormat: { ...defaultFormat },
  751. };
  752. let timer: any = 0;
  753. const shared = ref<boolean>(false);
  754. const qrcode = reactive({
  755. visible: false,
  756. url: '',
  757. });
  758. const publishDialog = reactive<any>({});
  759. const publishChargeDialog = reactive<any>({});
  760. const addDataDialog = reactive<any>({});
  761. onMounted(() => {
  762. meta2d = new Meta2d('meta2d', meta2dOptions);
  763. registerBasicDiagram();
  764. open(true);
  765. meta2d.on('active', active);
  766. meta2d.on('inactive', inactive);
  767. meta2d.on('scale', scaleListener);
  768. meta2d.on('add', lineAdd);
  769. meta2d.on('opened', openedListener);
  770. meta2d.on('undo', patchFlag);
  771. meta2d.on('redo', patchFlag);
  772. meta2d.on('add', patchFlag);
  773. meta2d.on('delete', patchFlag);
  774. meta2d.on('rotatePens', patchFlag);
  775. meta2d.on('translatePens', patchFlag);
  776. // 所有编辑栏所做修改
  777. meta2d.on('components-update-value', patchFlag);
  778. meta2d.on('contextmenu', onContextmenu);
  779. meta2d.on('click', canvasClick);
  780. timer = setInterval(autoSave, 60000);
  781. window.onbeforeunload = () => {
  782. autoSave();
  783. };
  784. });
  785. const watcher = watch(
  786. () => route.query,
  787. async () => {
  788. open();
  789. }
  790. );
  791. const open = async (flag: boolean = false) => {
  792. if (route.query.id) {
  793. let ret: any;
  794. if (route.query.c) {
  795. ret = await getComponents(route.query.id + '');
  796. } else {
  797. ret = await getLe5leV(route.query.id + '');
  798. }
  799. if (ret) {
  800. meta2d.open(ret);
  801. if (!route.query.c) {
  802. shared.value = ret.shared;
  803. const qr: any = await QRCode.toDataURL(
  804. `https://view2d.le5le.com/?id=${route.query.id + ''}`
  805. );
  806. qrcode.url = qr;
  807. }
  808. }
  809. } else if (flag) {
  810. const data: string = await localforage.getItem(localStorageName);
  811. if (data) {
  812. meta2d.open(JSON.parse(data));
  813. }
  814. } else {
  815. meta2d.open({ pens: [] } as any);
  816. }
  817. !meta2d.store.data.x && (meta2d.store.data.x = meta2d.store.options.x || 0);
  818. !meta2d.store.data.y && (meta2d.store.data.y = meta2d.store.options.y || 0);
  819. };
  820. const openedListener = () => {
  821. const {
  822. locked,
  823. scale: canvasScale,
  824. fromArrow: canvasFromArrow,
  825. toArrow: canvasToArrow,
  826. } = meta2d.store.data;
  827. isLock.value = locked || 0;
  828. scale.value = Math.round(canvasScale * 100);
  829. fromArrow.value = canvasFromArrow || '';
  830. toArrow.value = canvasToArrow || '';
  831. };
  832. const patchFlag = () => {
  833. setDot(true);
  834. };
  835. onUnmounted(() => {
  836. clearInterval(timer);
  837. watcher();
  838. if (meta2d) {
  839. meta2d.off('active', active);
  840. meta2d.off('inactive', inactive);
  841. meta2d.off('scale', scaleListener);
  842. meta2d.off('add', lineAdd);
  843. meta2d.on('opened', openedListener);
  844. meta2d.off('undo', patchFlag);
  845. meta2d.off('redo', patchFlag);
  846. meta2d.off('add', patchFlag);
  847. meta2d.off('delete', patchFlag);
  848. meta2d.off('rotatePens', patchFlag);
  849. meta2d.off('translatePens', patchFlag);
  850. meta2d.off('components-update-value', patchFlag);
  851. meta2d.off('contextmenu', onContextmenu);
  852. meta2d.off('click', canvasClick);
  853. meta2d.destroy();
  854. }
  855. });
  856. const inactive = () => {
  857. select();
  858. };
  859. const active = (pens: Pen[]) => {
  860. select(pens);
  861. //格式刷处理
  862. if (one.value || always.value) {
  863. meta2d.formatPainter();
  864. one.value = false;
  865. }
  866. };
  867. const one = ref(false);
  868. const always = ref(false);
  869. const oneFormat = () => {
  870. if (one.value) {
  871. one.value = false;
  872. } else {
  873. one.value = true;
  874. meta2d.setFormatPainter();
  875. }
  876. if (always.value) {
  877. always.value = false;
  878. one.value = false;
  879. }
  880. };
  881. const alwaysFormat = () => {
  882. always.value = true;
  883. };
  884. const clearFormat = () => {
  885. always.value = false;
  886. one.value = false;
  887. meta2d.clearFormatPainter();
  888. };
  889. const scale = ref(100);
  890. function scaleListener(newScale: number) {
  891. scale.value = Math.round(newScale * 100);
  892. }
  893. const dataDialog = reactive<any>({});
  894. const currentLineType = ref('curve');
  895. const lineTypes = reactive([
  896. { name: '曲线', icon: '#l-curve2', value: 'curve' },
  897. { name: '线段', icon: '#l-polyline', value: 'polyline' },
  898. { name: '直线', icon: '#l-line', value: 'line' },
  899. { name: '脑图曲线', icon: '#l-mind', value: 'mind' },
  900. ]);
  901. const changeLineType = (value: string) => {
  902. currentLineType.value = value;
  903. if (meta2d) {
  904. meta2d.store.options.drawingLineName = value;
  905. meta2d.canvas.drawingLineName && (meta2d.canvas.drawingLineName = value);
  906. meta2d.store.active?.forEach((pen) => {
  907. meta2d.updateLineType(pen, value);
  908. });
  909. }
  910. };
  911. const fromArrow = ref('');
  912. const fromArrows = [
  913. { icon: '#l-line', value: '' },
  914. { icon: '#l-from-triangle', value: 'triangle' },
  915. { icon: '#l-from-diamond', value: 'diamond' },
  916. { icon: '#l-from-circle', value: 'circle' },
  917. { icon: '#l-from-lineDown', value: 'lineDown' },
  918. { icon: '#l-from-lineUp', value: 'lineUp' },
  919. { icon: '#l-from-triangleSolid', value: 'triangleSolid' },
  920. { icon: '#l-from-diamondSolid', value: 'diamondSolid' },
  921. { icon: '#l-from-circleSolid', value: 'circleSolid' },
  922. { icon: '#l-from-line', value: 'line' },
  923. ];
  924. const toArrow = ref('');
  925. const toArrows = [
  926. { icon: '#l-line', value: '' },
  927. { icon: '#l-to-triangle', value: 'triangle' },
  928. { icon: '#l-to-diamond', value: 'diamond' },
  929. { icon: '#l-to-circle', value: 'circle' },
  930. { icon: '#l-to-lineDown', value: 'lineDown' },
  931. { icon: '#l-to-lineUp', value: 'lineUp' },
  932. { icon: '#l-to-triangleSolid', value: 'triangleSolid' },
  933. { icon: '#l-to-diamondSolid', value: 'diamondSolid' },
  934. { icon: '#l-to-circleSolid', value: 'circleSolid' },
  935. { icon: '#l-to-line', value: 'line' },
  936. ];
  937. const changeFromArrow = (value: string) => {
  938. fromArrow.value = value;
  939. // 画布默认值
  940. meta2d.store.data.fromArrow = value;
  941. // 活动层的箭头都变化
  942. if (meta2d.store.active) {
  943. meta2d.store.active.forEach((pen: Pen) => {
  944. if (pen.type === PenType.Line) {
  945. pen.fromArrow = value;
  946. meta2d.setValue(
  947. {
  948. id: pen.id,
  949. fromArrow: pen.fromArrow,
  950. },
  951. {
  952. render: false,
  953. }
  954. );
  955. }
  956. });
  957. meta2d.render();
  958. }
  959. };
  960. const changeToArrow = (value: string) => {
  961. toArrow.value = value;
  962. // 画布默认值
  963. meta2d.store.data.toArrow = value;
  964. // 活动层的箭头都变化
  965. if (meta2d.store.active) {
  966. meta2d.store.active.forEach((pen: Pen) => {
  967. if (pen.type === PenType.Line) {
  968. pen.toArrow = value;
  969. meta2d.setValue(
  970. {
  971. id: pen.id,
  972. toArrow: pen.toArrow,
  973. },
  974. {
  975. render: false,
  976. }
  977. );
  978. }
  979. });
  980. meta2d.render();
  981. }
  982. };
  983. const oneD = ref<boolean>(false);
  984. const alwaysD = ref<boolean>(false);
  985. const oneDraw = () => {
  986. if (oneD.value) {
  987. oneD.value = false;
  988. if (!alwaysD.value) {
  989. meta2d.finishDrawLine();
  990. meta2d.drawLine();
  991. meta2d.store.options.disableAnchor = true;
  992. }
  993. } else {
  994. oneD.value = true;
  995. meta2d.drawLine(meta2d.store.options.drawingLineName);
  996. meta2d.store.options.disableAnchor = false;
  997. }
  998. if (alwaysD.value) {
  999. meta2d.finishDrawLine();
  1000. meta2d.drawLine();
  1001. oneD.value = false;
  1002. alwaysD.value = false;
  1003. meta2d.store.options.disableAnchor = true;
  1004. }
  1005. };
  1006. const alwaysDraw = () => {
  1007. alwaysD.value = true;
  1008. meta2d.drawLine(meta2d.store.options.drawingLineName);
  1009. meta2d.store.options.disableAnchor = false;
  1010. };
  1011. const lineAdd = (pens: Pen[]) => {
  1012. if (pens.length === 1 && pens[0].name === 'line') {
  1013. //连线类型
  1014. if (oneD.value && !alwaysD.value) {
  1015. if (meta2d.canvas.drawingLineName) {
  1016. oneD.value = false;
  1017. setTimeout(() => {
  1018. meta2d.finishDrawLine();
  1019. meta2d.drawLine();
  1020. meta2d.store.options.disableAnchor = true;
  1021. }, 100);
  1022. }
  1023. }
  1024. }
  1025. };
  1026. const onAddShape = (event: DragEvent | MouseEvent, name: string) => {
  1027. let data: any;
  1028. if (name === 'text') {
  1029. data = {
  1030. text: 'text',
  1031. width: 100,
  1032. height: 20,
  1033. name: 'text',
  1034. };
  1035. } else if (name === 'line') {
  1036. data = {
  1037. anchors: [
  1038. { id: '0', x: 0, y: 0.5 },
  1039. { id: '1', x: 1, y: 0.5 },
  1040. ],
  1041. width: 100,
  1042. height: 1,
  1043. name: 'line',
  1044. lineName: 'line',
  1045. type: 1,
  1046. };
  1047. }
  1048. if (!(event as DragEvent).dataTransfer) {
  1049. meta2d.canvas.addCaches = deepClone([data]);
  1050. } else {
  1051. (event as DragEvent).dataTransfer?.setData('Meta2d', JSON.stringify(data));
  1052. }
  1053. event.stopPropagation();
  1054. };
  1055. const isLock = ref(0);
  1056. function onLock(lock: number) {
  1057. isLock.value = lock;
  1058. meta2d.lock(lock);
  1059. meta2d.hideInput();
  1060. }
  1061. const preview = async () => {
  1062. meta2d.stopAnimate();
  1063. // @ts-ignore
  1064. const data: Meta2dBackData = meta2d.data();
  1065. checkData(data);
  1066. if (dot && user && data._id) {
  1067. // 有 id ,是修改后保存
  1068. await save(SaveType.Save);
  1069. }
  1070. if (!data._id) {
  1071. await localforage.setItem(localStorageName, JSON.stringify(data));
  1072. }
  1073. router.push({
  1074. path: '/preview',
  1075. query: {
  1076. r: Date.now() + '',
  1077. id: data._id,
  1078. },
  1079. });
  1080. };
  1081. const contextmenu = reactive<any>({
  1082. visible: false,
  1083. type: '',
  1084. style: {},
  1085. });
  1086. const onContextmenu = ({ e, rect }: { e: any; rect: any }) => {
  1087. contextmenu.type = '';
  1088. contextmenu.style = {
  1089. left: e.clientX + 'px',
  1090. top: e.clientY + 'px',
  1091. };
  1092. if (
  1093. meta2d.store.hoverAnchor &&
  1094. meta2d.canvas.hoverType === HoverType.LineAnchor
  1095. ) {
  1096. contextmenu.type = 'anchor';
  1097. if (document.body.clientHeight - e.clientY < 128) {
  1098. contextmenu.style = {
  1099. left: e.clientX + 'px',
  1100. bottom: '4px',
  1101. };
  1102. }
  1103. } else {
  1104. contextmenu.type = 'pen';
  1105. if (document.body.clientHeight - e.clientY < 450) {
  1106. contextmenu.style = {
  1107. left: e.clientX + 'px',
  1108. bottom: '4px',
  1109. };
  1110. }
  1111. }
  1112. if (contextmenu.type) {
  1113. contextmenu.visible = true;
  1114. } else {
  1115. contextmenu.visible = false;
  1116. }
  1117. };
  1118. const canvasClick = () => {
  1119. contextmenu.visible = false;
  1120. };
  1121. const changeContextMenuVisible = (e: boolean) => {
  1122. contextmenu.visible = e;
  1123. };
  1124. const networkColumns = ref([
  1125. {
  1126. colKey: 'name',
  1127. title: '名称',
  1128. ellipsis: true,
  1129. width: 160,
  1130. },
  1131. {
  1132. colKey: 'type',
  1133. title: '类型',
  1134. width: 120,
  1135. },
  1136. {
  1137. colKey: 'url',
  1138. title: 'URL地址',
  1139. ellipsis: true,
  1140. },
  1141. { colKey: 'actions', title: '操作', width: 100 },
  1142. ]);
  1143. const onShowDataDialog = () => {
  1144. // @ts-ignore
  1145. dataDialog.networks = meta2d.store.data.networks || [];
  1146. // @ts-ignore
  1147. dataDialog.dataset = meta2d.store.data.dataset;
  1148. dataDialog.networkList = [];
  1149. dataDialog.editNetwork = false;
  1150. dataDialog.save = true;
  1151. dataDialog.show = true;
  1152. getNetworks();
  1153. };
  1154. const onSelectNetWork = (item: any) => {
  1155. dataDialog.networks.push(item);
  1156. dataDialog.popupVisible = false;
  1157. };
  1158. const onInputNetwork = (text: string) => {
  1159. debounce(getNetworks, 300);
  1160. };
  1161. // 请求我的数据源接口
  1162. const getNetworks = async () => {
  1163. // const ret: any = await axios.get(`/api/xxx`);
  1164. // if (ret) {
  1165. // dataDialog.networkList = ret.list
  1166. // }
  1167. };
  1168. const addNetwork = () => {
  1169. dataDialog.network = {
  1170. name: '',
  1171. type: '',
  1172. url: '',
  1173. options: {
  1174. clientId: '',
  1175. username: '',
  1176. password: '',
  1177. customClientId: false,
  1178. },
  1179. };
  1180. dataDialog.editNetwork = 1;
  1181. };
  1182. const editNetwork = (data: any) => {
  1183. dataDialog.network = data;
  1184. dataDialog.editNetwork = 2;
  1185. };
  1186. const deleteNetwork = (index: number) => {
  1187. dataDialog.networks.splice(index, 1);
  1188. meta2d.connectSocket();
  1189. };
  1190. const onOkNetwork = () => {
  1191. if (dataDialog.editNetwork === 1) {
  1192. dataDialog.networks.push(dataDialog.network);
  1193. }
  1194. dataDialog.editNetwork = false;
  1195. // 保存到我的数据源
  1196. if (dataDialog.save) {
  1197. // todo
  1198. }
  1199. };
  1200. const datasetColumns = ref([
  1201. {
  1202. colKey: 'label',
  1203. title: '名称(数据ID)',
  1204. ellipsis: true,
  1205. },
  1206. {
  1207. colKey: 'type',
  1208. title: '类型',
  1209. ellipsis: true,
  1210. },
  1211. {
  1212. colKey: 'value',
  1213. title: '值',
  1214. ellipsis: true,
  1215. },
  1216. {
  1217. colKey: 'actions',
  1218. title: '操作',
  1219. width: 80,
  1220. },
  1221. ]);
  1222. const importDataset = async () => {
  1223. let columns: any = [
  1224. {
  1225. header: '名称',
  1226. key: 'label',
  1227. },
  1228. {
  1229. header: '数据ID',
  1230. key: 'key',
  1231. },
  1232. {
  1233. header: '类型',
  1234. key: 'type',
  1235. },
  1236. {
  1237. header: '场景',
  1238. key: 'case',
  1239. },
  1240. {
  1241. header: '值',
  1242. key: 'value',
  1243. },
  1244. ];
  1245. const data: any = await importExcel(columns);
  1246. dataDialog.dataset = data;
  1247. };
  1248. const showAddData = (row?: any) => {
  1249. if (row) {
  1250. addDataDialog.header = '编辑数据';
  1251. addDataDialog.data = row;
  1252. } else {
  1253. addDataDialog.header = '添加数据';
  1254. addDataDialog.data = { type: 'string' };
  1255. }
  1256. addDataDialog.show = true;
  1257. };
  1258. const onOkAddData = () => {
  1259. if (!addDataDialog.data.label) {
  1260. MessagePlugin.error('请填写名称');
  1261. return;
  1262. }
  1263. if (!addDataDialog.data.key) {
  1264. MessagePlugin.error('请填写数据ID');
  1265. return;
  1266. }
  1267. if (!dataDialog.dataset) {
  1268. dataDialog.dataset = [];
  1269. }
  1270. dataDialog.dataset.push(addDataDialog.data);
  1271. addDataDialog.show = false;
  1272. };
  1273. const share = async () => {
  1274. if (!route.query.id) {
  1275. MessagePlugin.error('请先保存!');
  1276. return;
  1277. }
  1278. const ret: any = await updateCollection('le5leV', {
  1279. _id: route.query.id,
  1280. shared: !shared.value,
  1281. });
  1282. if (ret) {
  1283. shared.value = ret.shared;
  1284. }
  1285. };
  1286. let qrTimer: any;
  1287. const onEnterQrcode = () => {
  1288. if (!qrcode.visible && !qrTimer) {
  1289. qrTimer = setTimeout(() => {
  1290. qrTimer = undefined;
  1291. qrcode.visible = true;
  1292. }, 300);
  1293. }
  1294. };
  1295. const onLeaveQrcode = () => {
  1296. if (qrTimer) {
  1297. clearTimeout(qrTimer);
  1298. qrTimer = undefined;
  1299. }
  1300. };
  1301. const onShowPublish = async () => {
  1302. // @ts-ignore
  1303. publishDialog.name = meta2d.store.data.name;
  1304. publishDialog.status = '';
  1305. publishDialog.tips = '';
  1306. publishDialog.id = route.query.id + '';
  1307. publishDialog.show = true;
  1308. const ret: any = await axios.post(`/api/domain/get`, {
  1309. id: publishDialog.id,
  1310. });
  1311. if (ret) {
  1312. if (ret.expired) {
  1313. const expired = new Date(ret.expired);
  1314. if (expired > new Date()) {
  1315. ret.isExpired = false;
  1316. } else if (expired > new Date('2023-01-17T08:00:00+08:00')) {
  1317. ret.isExpired = true;
  1318. } else {
  1319. ret.expired = undefined;
  1320. }
  1321. if (ret.expired) {
  1322. ret.expired = dayjs(ret.expired).format('YYYY-MM-DD HH:mm:ss');
  1323. }
  1324. }
  1325. publishDialog.data = ret;
  1326. makePublishQrcode();
  1327. }
  1328. };
  1329. const refreshSubdomain = async () => {
  1330. publishDialog.data.subDomain = s8();
  1331. onChangeSubdomain();
  1332. };
  1333. const onChangeSubdomain = async () => {
  1334. if (!publishDialog.data.subDomain) {
  1335. publishDialog.status = 'error';
  1336. publishDialog.tips = '请填写子域名';
  1337. }
  1338. const ret: any = await axios.post(`/api/domain/exists`, {
  1339. subDomain: publishDialog.data.subDomain,
  1340. });
  1341. if (ret && ret.id) {
  1342. publishDialog.status = 'error';
  1343. publishDialog.tips = '已经存在相同子域名';
  1344. } else {
  1345. publishDialog.status = '';
  1346. publishDialog.tips = '';
  1347. }
  1348. if (
  1349. !publishDialog.data.domain ||
  1350. publishDialog.data.domain.indexOf('.v.le5le.com') >= 0
  1351. ) {
  1352. publishDialog.data.domain = publishDialog.data.subDomain + '.v.le5le.com';
  1353. }
  1354. makePublishQrcode();
  1355. };
  1356. const onPublish = async () => {
  1357. if (publishDialog.status) {
  1358. return;
  1359. }
  1360. if (!publishDialog.data.subDomain) {
  1361. publishDialog.status = 'error';
  1362. publishDialog.tips = '请填写子域名';
  1363. }
  1364. if (!publishDialog.data.domain) {
  1365. publishDialog.data.domain = publishDialog.data.subDomain + '.v.le5le.com';
  1366. }
  1367. const ret: any = await axios.post(`/api/domain/set`, {
  1368. id: route.query.id,
  1369. subDomain: publishDialog.data.subDomain,
  1370. domain: publishDialog.data.domain,
  1371. });
  1372. if (ret) {
  1373. if (ret.expired) {
  1374. const expired = new Date(ret.expired);
  1375. if (expired > new Date()) {
  1376. ret.isExpired = false;
  1377. } else if (expired > new Date('2023-01-17T08:00:00+08:00')) {
  1378. ret.isExpired = true;
  1379. } else {
  1380. ret.expired = undefined;
  1381. }
  1382. if (ret.expired) {
  1383. ret.expired = dayjs(ret.expired).format('YYYY-MM-DD HH:mm:ss');
  1384. }
  1385. }
  1386. publishDialog.data = ret;
  1387. makePublishQrcode();
  1388. }
  1389. };
  1390. const makePublishQrcode = async () => {
  1391. const qr: any = await QRCode.toDataURL(`http://${publishDialog.data.domain}`);
  1392. publishDialog.url = qr;
  1393. };
  1394. const onSuccessChargeCloud = () => {
  1395. publishChargeDialog.show = false;
  1396. onShowPublish();
  1397. };
  1398. </script>
  1399. <style lang="postcss" scoped>
  1400. .meta2d {
  1401. display: flex;
  1402. flex-direction: column;
  1403. background-color: var(--color-background-editor);
  1404. border-left: 1px solid var(--color-border);
  1405. .tools {
  1406. display: flex;
  1407. font-size: 12px;
  1408. background-color: var(--color-background);
  1409. height: 40px;
  1410. flex-shrink: 0;
  1411. padding: 0 12px;
  1412. a {
  1413. display: flex;
  1414. align-items: center;
  1415. height: 100%;
  1416. padding: 0 10px;
  1417. color: var(--color);
  1418. text-decoration: none;
  1419. .l-icon {
  1420. width: 16px;
  1421. height: 16px;
  1422. }
  1423. &:hover {
  1424. color: var(--color-primary);
  1425. }
  1426. }
  1427. .t-icon {
  1428. font-size: 16px;
  1429. }
  1430. }
  1431. #meta2d {
  1432. border-top: 1px solid var(--color-background-input);
  1433. height: calc(100vh - 81px);
  1434. :deep(.meta2d-map) {
  1435. background: var(--color-background);
  1436. }
  1437. }
  1438. }
  1439. </style>