View.vue 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683
  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="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="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="onScaleFull"><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 v-model="dataDialog.tab" class="body">
  285. <t-tab-panel :value="1" label="实时数据" :destroy-on-hide="false">
  286. <template #panel>
  287. <div v-if="!dataDialog.editNetwork">
  288. <div class="mt-16 flex between middle">
  289. <div>
  290. <t-checkbox
  291. v-model="dataDialog.enableMock"
  292. @change="onChangeMock"
  293. >
  294. 开启模拟数据
  295. </t-checkbox>
  296. </div>
  297. <div>
  298. <t-select-input
  299. v-model:inputValue="dataDialog.input"
  300. placeholder="搜索我的实时数据"
  301. allow-input
  302. clearable
  303. :popup-visible="dataDialog.popupVisible"
  304. @focus="dataDialog.popupVisible = true"
  305. @blur="dataDialog.popupVisible = undefined"
  306. @input-change="onInputNetwork"
  307. style="width: 240px"
  308. >
  309. <template #panel>
  310. <ul style="padding: 4px">
  311. <li
  312. class="hover-background item"
  313. v-for="(item, i) in dataDialog.networkList"
  314. :key="item.url"
  315. @click="onSelectNetWork(item)"
  316. >
  317. 名称: {{ item.name }}
  318. <div class="desc">地址: {{ item.url }}</div>
  319. <span class="del" @click.stop="onDelNetWork(item, i)">
  320. <t-icon name="delete" />
  321. </span>
  322. </li>
  323. <li
  324. v-if="dataDialog.networkList.length >= 10"
  325. style="
  326. line-height: 1.5;
  327. padding: 8px;
  328. border-radius: 2px;
  329. "
  330. :key="-1"
  331. >
  332. <div class="desc">...</div>
  333. </li>
  334. <li
  335. v-if="!dataDialog.networkList.length"
  336. style="
  337. line-height: 1.5;
  338. padding: 8px;
  339. border-radius: 2px;
  340. "
  341. :key="-1"
  342. >
  343. <div class="desc">暂无数据</div>
  344. </li>
  345. </ul>
  346. </template>
  347. <template #suffixIcon>
  348. <t-icon name="search" class="hover" />
  349. </template>
  350. </t-select-input>
  351. <t-button
  352. class="ml-12"
  353. style="height: 30px"
  354. @click="addNetwork"
  355. >
  356. 添加实时数据
  357. </t-button>
  358. </div>
  359. </div>
  360. <t-table
  361. class="mt-12"
  362. row-key="id"
  363. :data="dataDialog.networks"
  364. :columns="networkColumns"
  365. :max-height="280"
  366. size="small"
  367. >
  368. <template #protocol="{ row, rowIndex }">
  369. {{ row.protocol || 'MQTT' }}
  370. </template>
  371. <template #actions="{ row, rowIndex }">
  372. <a @click="editNetwork(row)"> 编辑 </a>
  373. <a class="ml-12" @click="deleteNetwork(rowIndex)"> 删除 </a>
  374. </template>
  375. <template #empty>
  376. <div class="center">
  377. <div>暂无数据</div>
  378. <div class="mt-8">
  379. <a @click="addNetwork"> + 添加实时数据</a>
  380. </div>
  381. </div>
  382. </template>
  383. </t-table>
  384. </div>
  385. <div v-else>
  386. <div class="mt-8">
  387. <a
  388. @click="
  389. dataDialog.network = dataDialog.networkBak;
  390. dataDialog.editNetwork = false;
  391. "
  392. class="flex middle"
  393. style="width: 44px"
  394. >
  395. <t-icon name="rollback" class="mr-4" /> 返回
  396. </a>
  397. </div>
  398. <div style="height: 300px; overflow-y: auto">
  399. <Network v-model="dataDialog.network" />
  400. </div>
  401. </div>
  402. </template>
  403. </t-tab-panel>
  404. <t-tab-panel :value="2" :destroy-on-hide="false">
  405. <template #label> 数据集 </template>
  406. <template #panel>
  407. <template v-if="!dataDialog.editDataset">
  408. <div class="form-item mt-16">
  409. <label style="width: 100px"> 当前数据集 </label>
  410. <div class="flex w-full">
  411. <t-select
  412. class="flex-grow"
  413. v-model="dataDialog.datasetId"
  414. filterable
  415. placeholder="选择数据集"
  416. :on-search="onInputDatasets"
  417. :popup-props="{ overlayClassName: 'select-options' }"
  418. @change="onSelDataset()"
  419. >
  420. <t-option
  421. v-for="(item, i) in dataDialog.datasetList"
  422. :key="item.id"
  423. :value="item.id"
  424. :label="item.name"
  425. >
  426. <div class="hover-background item">
  427. 名称: {{ item.name }}
  428. <div v-if="item.url" class="desc">
  429. URL: {{ item.url }}
  430. </div>
  431. <div v-else class="desc">自定义</div>
  432. <span class="del" @click.stop="onDelDataset(item, i)">
  433. <t-icon name="delete" />
  434. </span>
  435. </div>
  436. </t-option>
  437. <t-option
  438. v-if="dataDialog.datasetList.length >= 10"
  439. :disabled="true"
  440. >
  441. <div class="ml-8 gray">...</div>
  442. </t-option>
  443. </t-select>
  444. <t-button
  445. class="ml-12 shrink-0"
  446. style="height: 30px"
  447. @click="addDataset"
  448. >
  449. 添加数据集
  450. </t-button>
  451. </div>
  452. </div>
  453. <t-table
  454. class="mt-12"
  455. row-key="id"
  456. :data="dataDialog.dataset.data"
  457. :columns="datasetColumns"
  458. size="small"
  459. :max-height="280"
  460. >
  461. <template #type="{ row }">
  462. {{ row.type || 'string' }}
  463. </template>
  464. </t-table>
  465. </template>
  466. <div v-else>
  467. <div class="mt-8">
  468. <a
  469. @click="
  470. dataDialog.dataset = dataDialog.datasetBak;
  471. dataDialog.datasetId = dataDialog.dataset.id;
  472. dataDialog.editDataset = 0;
  473. "
  474. class="flex middle"
  475. style="width: 44px"
  476. >
  477. <t-icon name="rollback" class="mr-4" /> 返回
  478. </a>
  479. </div>
  480. <div style="height: 300px; overflow-y: auto">
  481. <Dataset v-model="dataDialog.dataset" />
  482. </div>
  483. </div>
  484. </template>
  485. </t-tab-panel>
  486. </t-tabs>
  487. <template #footer>
  488. <div
  489. v-if="dataDialog.tab === 1 && dataDialog.editNetwork"
  490. class="flex middle"
  491. >
  492. <div class="flex-grow"></div>
  493. <t-checkbox v-model="dataDialog.save" class="mr-12">
  494. 同时保存到我的实时数据
  495. </t-checkbox>
  496. <t-button @click="onOkNetwork">确定</t-button>
  497. </div>
  498. <div v-else-if="dataDialog.tab === 2" class="flex middle">
  499. <template v-if="dataDialog.editDataset === 1">
  500. <div class="flex-grow"></div>
  501. <t-checkbox v-model="dataDialog.save" class="mr-12">
  502. 同时保存为我的数据集
  503. </t-checkbox>
  504. <t-button @click="onOkDataset()">保存</t-button>
  505. </template>
  506. <template v-else-if="dataDialog.editDataset === 2">
  507. <div class="flex-grow"></div>
  508. <t-button @click="onOkDataset(true)"> 另外为新数据集 </t-button>
  509. <t-button @click="onOkDataset()">保存</t-button>
  510. </template>
  511. <template v-else>
  512. <a v-if="dataDialog.dataset.id" @click="editDataset">
  513. 编辑当前数据集
  514. </a>
  515. <div class="flex-grow"></div>
  516. <t-button @click="dataDialog.show = false"> 完成 </t-button>
  517. </template>
  518. </div>
  519. <div v-else class="flex middle">
  520. <div class="flex-grow"></div>
  521. <t-button @click="onFinishDataDialog"> 完成 </t-button>
  522. </div>
  523. </template>
  524. </t-dialog>
  525. <t-dialog
  526. v-if="publishDialog.show"
  527. width="700px"
  528. header="云发布"
  529. :visible="true"
  530. :cancel-btn="null"
  531. :confirm-btn="'完成'"
  532. @close="publishDialog.show = false"
  533. @confirm="publishDialog.show = false"
  534. >
  535. <div class="body" style="height: 350px">
  536. <div class="form-item mt-8">
  537. <label>项目名称</label>
  538. <div class="flex middle">
  539. <t-icon name="laptop" class="mr-8" /> {{ publishDialog.name }}
  540. </div>
  541. </div>
  542. <template v-if="publishDialog.data">
  543. <div class="form-item mt-8">
  544. <label>发布状态</label>
  545. <div v-if="publishDialog.data.id" class="flex middle">
  546. <div v-if="publishDialog.data.isExpired" class="warning">
  547. <t-icon name="stop-circle-1" class="mr-4" />
  548. 已过期
  549. </div>
  550. <div v-else class="primary">
  551. <t-icon name="play-circle" class="mr-4" />
  552. 正在运行
  553. </div>
  554. <div class="gray" style="margin-left: 32px; margin-top: -2px">
  555. 有效期至:{{ publishDialog.data.expired }}
  556. </div>
  557. <a class="bland ml-12" @click="publishChargeDialog.show = true">
  558. 续费
  559. </a>
  560. </div>
  561. <div v-else class="flex middle">
  562. <t-icon name="play-circle-stroke" class="mr-4" />
  563. 未发布
  564. </div>
  565. </div>
  566. <div class="form-item mt-16">
  567. <label>乐吾乐域名</label>
  568. <div class="flex w-full">
  569. <t-input
  570. v-model="publishDialog.data.subDomain"
  571. :maxlength="16"
  572. :status="publishDialog.status"
  573. :tips="publishDialog.tips"
  574. class="mr-4"
  575. style="width: 350px"
  576. placeholder="子域名"
  577. @change="onChangeSubdomain"
  578. />
  579. <t-tooltip content="随机生成">
  580. <t-icon
  581. name="refresh"
  582. class="hover"
  583. @click="refreshSubdomain"
  584. />
  585. </t-tooltip>
  586. <div class="mt-4 ml-16">v.le5le.com</div>
  587. </div>
  588. </div>
  589. <div class="form-item mt-24">
  590. <label>访问域名</label>
  591. <div class="w-full">
  592. <div class="flex middle">
  593. <t-input
  594. v-model="publishDialog.data.domain"
  595. style="width: 350px"
  596. placeholder="支持自定义域名"
  597. />
  598. <template v-if="publishDialog.data.domain">
  599. <a
  600. :href="`http://${publishDialog.data.domain}`"
  601. target="_blank"
  602. class="hover"
  603. style="margin-left: 36px; text-decoration: underline"
  604. >
  605. 点击访问
  606. </a>
  607. <t-popup
  608. placement="bottom"
  609. v-model="publishDialog.qrcodeVisible"
  610. >
  611. <a class="hover" style="margin-left: 32px">
  612. <t-icon name="qrcode" />
  613. <span
  614. style="margin-left: 2px; position: relative; top: 1px"
  615. >
  616. 手机访问
  617. </span>
  618. </a>
  619. <template #content>
  620. <div style="padding: 12px 12px 6px 12px">
  621. <img :src="publishDialog.url" />
  622. </div>
  623. </template>
  624. </t-popup>
  625. </template>
  626. </div>
  627. <div class="desc mt-12">
  628. <div class="title desc">- 注意</div>
  629. <div>仅支持48小时免费试用,到期后需要续费使用。</div>
  630. </div>
  631. <div class="desc mt-8">
  632. <div class="title desc">- 自定义域名</div>
  633. <div>
  634. 在域名服务商的DNS控制台设置好对应的CNAME,值为乐吾乐域名。
  635. <a
  636. href="https://doc.le5le.com/document/126505408"
  637. target="_blank"
  638. >
  639. 更多帮助
  640. </a>
  641. </div>
  642. </div>
  643. </div>
  644. </div>
  645. <div class="form-item mt-16">
  646. <label></label>
  647. <div class="w-full">
  648. <t-button @click="onPublish">发布</t-button>
  649. </div>
  650. </div>
  651. </template>
  652. <div v-else class="flex center" style="margin-top: 32px">
  653. <t-loading text="加载中..." size="small"></t-loading>
  654. </div>
  655. </div>
  656. </t-dialog>
  657. <t-dialog
  658. v-if="publishChargeDialog.show"
  659. v-model:visible="publishChargeDialog.show"
  660. header="云发布续费"
  661. :close-on-overlay-click="false"
  662. :width="700"
  663. :footer="false"
  664. >
  665. <ChargeCloudPublish
  666. :projectId="publishDialog.id"
  667. @success="onSuccessChargeCloud"
  668. />
  669. </t-dialog>
  670. </div>
  671. </template>
  672. <script lang="ts" setup>
  673. import { onMounted, onUnmounted, watch, ref, reactive } from 'vue';
  674. import { useRouter, useRoute } from 'vue-router';
  675. import {
  676. Meta2d,
  677. Options,
  678. Pen,
  679. deepClone,
  680. PenType,
  681. HoverType,
  682. } from '@meta2d/core';
  683. import localforage from 'localforage';
  684. import dayjs from 'dayjs';
  685. import QRCode from 'qrcode';
  686. import axios from 'axios';
  687. import { MessagePlugin } from 'tdesign-vue-next';
  688. import { registerBasicDiagram } from '@/services/register';
  689. import { useUser } from '@/services/user';
  690. import {
  691. cdn,
  692. getComponents,
  693. getLe5leV,
  694. updateCollection,
  695. } from '@/services/api';
  696. import {
  697. save,
  698. autoSave,
  699. newFile,
  700. SaveType,
  701. onScaleFull,
  702. onScaleWindow,
  703. useDot,
  704. } from '@/services/common';
  705. import { useSelection } from '@/services/selections';
  706. import { defaultFormat } from '@/services/defaults';
  707. import { checkData, localStorageName, Meta2dBackData } from '@/services/utils';
  708. import { debounce } from '@/services/debouce';
  709. import { s8 } from '@/services/random';
  710. import { setCookie } from '@/services/cookie';
  711. import ContextMenu from './ContextMenu.vue';
  712. import Network from './Network.vue';
  713. import Dataset from './Dataset.vue';
  714. import ChargeCloudPublish from './ChargeCloudPublish.vue';
  715. const router = useRouter();
  716. const route = useRoute();
  717. const { user } = useUser();
  718. const { dot, setDot } = useDot();
  719. const { select } = useSelection();
  720. const meta2dOptions: Options = {
  721. cdn,
  722. rule: true,
  723. background: '#1e2430',
  724. x: 32,
  725. y: 32,
  726. width: 1920,
  727. height: 1080,
  728. color: '#bdc7db',
  729. disableAnchor: true,
  730. defaultFormat: { ...defaultFormat },
  731. };
  732. let timer: any = 0;
  733. const shared = ref<boolean>(false);
  734. const qrcode = reactive({
  735. visible: false,
  736. url: '',
  737. });
  738. const publishDialog = reactive<any>({});
  739. const publishChargeDialog = reactive<any>({});
  740. onMounted(() => {
  741. meta2d = new Meta2d('meta2d', meta2dOptions);
  742. registerBasicDiagram();
  743. open(true);
  744. meta2d.on('active', active);
  745. meta2d.on('inactive', inactive);
  746. meta2d.on('scale', scaleSubscriber);
  747. meta2d.on('add', lineAdd);
  748. meta2d.on('opened', openedListener);
  749. meta2d.on('undo', patchFlag);
  750. meta2d.on('redo', patchFlag);
  751. meta2d.on('add', patchFlag);
  752. meta2d.on('delete', patchFlag);
  753. meta2d.on('rotatePens', patchFlag);
  754. meta2d.on('translatePens', patchFlag);
  755. // 所有编辑栏所做修改
  756. meta2d.on('components-update-value', patchFlag);
  757. meta2d.on('contextmenu', onContextmenu);
  758. meta2d.on('click', canvasClick);
  759. timer = setInterval(autoSave, 60000);
  760. window.onbeforeunload = () => {
  761. autoSave();
  762. };
  763. });
  764. const watcher = watch(
  765. () => route.query,
  766. async () => {
  767. open();
  768. }
  769. );
  770. const open = async (flag: boolean = false) => {
  771. if (route.query.token) {
  772. localStorage.setItem('token', route.query.token + '');
  773. setCookie('token', route.query.token + '');
  774. const newQuery = { ...route.query };
  775. delete newQuery.token;
  776. router.replace({
  777. path: '/',
  778. query: newQuery,
  779. });
  780. return;
  781. }
  782. if (route.query.id) {
  783. let ret: any;
  784. if (route.query.c) {
  785. ret = await getComponents(route.query.id + '');
  786. } else {
  787. ret = await getLe5leV(route.query.id + '');
  788. }
  789. if (ret) {
  790. meta2d.open(ret);
  791. if (!route.query.c) {
  792. shared.value = ret.shared;
  793. const qr: any = await QRCode.toDataURL(
  794. `https://view2d.le5le.com/?id=${route.query.id + ''}`
  795. );
  796. qrcode.url = qr;
  797. }
  798. }
  799. } else if (flag) {
  800. const data: string = await localforage.getItem(localStorageName);
  801. if (data) {
  802. meta2d.open(JSON.parse(data));
  803. }
  804. } else if (!sessionStorage.getItem('opening')) {
  805. meta2d.open({ name: '新建项目', pens: [], enableMock: true } as any);
  806. }
  807. sessionStorage.removeItem('opening');
  808. !meta2d.store.data.x && (meta2d.store.data.x = meta2d.store.options.x || 0);
  809. !meta2d.store.data.y && (meta2d.store.data.y = meta2d.store.options.y || 0);
  810. };
  811. const openedListener = () => {
  812. const {
  813. locked,
  814. scale: canvasScale,
  815. fromArrow: canvasFromArrow,
  816. toArrow: canvasToArrow,
  817. } = meta2d.store.data;
  818. isLock.value = locked || 0;
  819. scale.value = Math.round(canvasScale * 100);
  820. fromArrow.value = canvasFromArrow || '';
  821. toArrow.value = canvasToArrow || '';
  822. };
  823. const patchFlag = () => {
  824. setDot();
  825. };
  826. onUnmounted(() => {
  827. clearInterval(timer);
  828. watcher();
  829. if (meta2d) {
  830. meta2d.destroy();
  831. }
  832. });
  833. const inactive = () => {
  834. select();
  835. };
  836. const active = (pens: Pen[]) => {
  837. select(pens);
  838. //格式刷处理
  839. if (one.value || always.value) {
  840. meta2d.formatPainter();
  841. one.value = false;
  842. }
  843. };
  844. const one = ref(false);
  845. const always = ref(false);
  846. const oneFormat = () => {
  847. if (one.value) {
  848. one.value = false;
  849. } else {
  850. one.value = true;
  851. meta2d.setFormatPainter();
  852. }
  853. if (always.value) {
  854. always.value = false;
  855. one.value = false;
  856. }
  857. };
  858. const alwaysFormat = () => {
  859. always.value = true;
  860. };
  861. const clearFormat = () => {
  862. always.value = false;
  863. one.value = false;
  864. meta2d.clearFormatPainter();
  865. };
  866. const scale = ref(100);
  867. const scaleSubscriber = (val: number) => {
  868. scale.value = Math.round(val * 100);
  869. };
  870. const dataDialog = reactive<any>({
  871. tab: 1,
  872. });
  873. const currentLineType = ref('curve');
  874. const lineTypes = reactive([
  875. { name: '曲线', icon: '#l-curve2', value: 'curve' },
  876. { name: '线段', icon: '#l-polyline', value: 'polyline' },
  877. { name: '直线', icon: '#l-line', value: 'line' },
  878. { name: '脑图曲线', icon: '#l-mind', value: 'mind' },
  879. ]);
  880. const changeLineType = (value: string) => {
  881. currentLineType.value = value;
  882. if (meta2d) {
  883. meta2d.store.options.drawingLineName = value;
  884. meta2d.canvas.drawingLineName && (meta2d.canvas.drawingLineName = value);
  885. meta2d.store.active?.forEach((pen) => {
  886. meta2d.updateLineType(pen, value);
  887. });
  888. }
  889. };
  890. const fromArrow = ref('');
  891. const fromArrows = [
  892. { icon: '#l-line', value: '' },
  893. { icon: '#l-from-triangle', value: 'triangle' },
  894. { icon: '#l-from-diamond', value: 'diamond' },
  895. { icon: '#l-from-circle', value: 'circle' },
  896. { icon: '#l-from-lineDown', value: 'lineDown' },
  897. { icon: '#l-from-lineUp', value: 'lineUp' },
  898. { icon: '#l-from-triangleSolid', value: 'triangleSolid' },
  899. { icon: '#l-from-diamondSolid', value: 'diamondSolid' },
  900. { icon: '#l-from-circleSolid', value: 'circleSolid' },
  901. { icon: '#l-from-line', value: 'line' },
  902. ];
  903. const toArrow = ref('');
  904. const toArrows = [
  905. { icon: '#l-line', value: '' },
  906. { icon: '#l-to-triangle', value: 'triangle' },
  907. { icon: '#l-to-diamond', value: 'diamond' },
  908. { icon: '#l-to-circle', value: 'circle' },
  909. { icon: '#l-to-lineDown', value: 'lineDown' },
  910. { icon: '#l-to-lineUp', value: 'lineUp' },
  911. { icon: '#l-to-triangleSolid', value: 'triangleSolid' },
  912. { icon: '#l-to-diamondSolid', value: 'diamondSolid' },
  913. { icon: '#l-to-circleSolid', value: 'circleSolid' },
  914. { icon: '#l-to-line', value: 'line' },
  915. ];
  916. const changeFromArrow = (value: string) => {
  917. fromArrow.value = value;
  918. // 画布默认值
  919. meta2d.store.data.fromArrow = value;
  920. // 活动层的箭头都变化
  921. if (meta2d.store.active) {
  922. meta2d.store.active.forEach((pen: Pen) => {
  923. if (pen.type === PenType.Line) {
  924. pen.fromArrow = value;
  925. meta2d.setValue(
  926. {
  927. id: pen.id,
  928. fromArrow: pen.fromArrow,
  929. },
  930. {
  931. render: false,
  932. }
  933. );
  934. }
  935. });
  936. meta2d.render();
  937. }
  938. };
  939. const changeToArrow = (value: string) => {
  940. toArrow.value = value;
  941. // 画布默认值
  942. meta2d.store.data.toArrow = value;
  943. // 活动层的箭头都变化
  944. if (meta2d.store.active) {
  945. meta2d.store.active.forEach((pen: Pen) => {
  946. if (pen.type === PenType.Line) {
  947. pen.toArrow = value;
  948. meta2d.setValue(
  949. {
  950. id: pen.id,
  951. toArrow: pen.toArrow,
  952. },
  953. {
  954. render: false,
  955. }
  956. );
  957. }
  958. });
  959. meta2d.render();
  960. }
  961. };
  962. const oneD = ref<boolean>(false);
  963. const alwaysD = ref<boolean>(false);
  964. const oneDraw = () => {
  965. if (oneD.value) {
  966. oneD.value = false;
  967. if (!alwaysD.value) {
  968. meta2d.finishDrawLine();
  969. meta2d.drawLine();
  970. meta2d.store.options.disableAnchor = true;
  971. }
  972. } else {
  973. oneD.value = true;
  974. meta2d.drawLine(meta2d.store.options.drawingLineName);
  975. meta2d.store.options.disableAnchor = false;
  976. }
  977. if (alwaysD.value) {
  978. meta2d.finishDrawLine();
  979. meta2d.drawLine();
  980. oneD.value = false;
  981. alwaysD.value = false;
  982. meta2d.store.options.disableAnchor = true;
  983. }
  984. };
  985. const alwaysDraw = () => {
  986. alwaysD.value = true;
  987. meta2d.drawLine(meta2d.store.options.drawingLineName);
  988. meta2d.store.options.disableAnchor = false;
  989. };
  990. const lineAdd = (pens: Pen[]) => {
  991. if (pens.length === 1 && pens[0].name === 'line') {
  992. //连线类型
  993. if (oneD.value && !alwaysD.value) {
  994. if (meta2d.canvas.drawingLineName) {
  995. oneD.value = false;
  996. setTimeout(() => {
  997. meta2d.finishDrawLine();
  998. meta2d.drawLine();
  999. meta2d.store.options.disableAnchor = true;
  1000. }, 100);
  1001. }
  1002. }
  1003. }
  1004. };
  1005. const onAddShape = (event: DragEvent | MouseEvent, name: string) => {
  1006. event.stopPropagation();
  1007. let data: any;
  1008. if (name === 'text') {
  1009. data = {
  1010. text: 'text',
  1011. width: 100,
  1012. height: 20,
  1013. name: 'text',
  1014. };
  1015. } else if (name === 'line') {
  1016. data = {
  1017. anchors: [
  1018. { id: '0', x: 1, y: 0 },
  1019. { id: '1', x: 0, y: 1 },
  1020. ],
  1021. width: 100,
  1022. height: 100,
  1023. name: 'line',
  1024. lineName: 'line',
  1025. type: 1,
  1026. };
  1027. }
  1028. if (!(event as DragEvent).dataTransfer) {
  1029. meta2d.canvas.addCaches = deepClone([data]);
  1030. } else {
  1031. (event as DragEvent).dataTransfer?.setData('Meta2d', JSON.stringify(data));
  1032. }
  1033. };
  1034. const isLock = ref(0);
  1035. function onLock(lock: number) {
  1036. isLock.value = lock;
  1037. meta2d.lock(lock);
  1038. meta2d.hideInput();
  1039. }
  1040. const preview = async () => {
  1041. meta2d.stopAnimate();
  1042. // @ts-ignore
  1043. const data: Meta2dBackData = meta2d.data();
  1044. checkData(data);
  1045. if (dot && user && data._id) {
  1046. // 有 id ,是修改后保存
  1047. await save(SaveType.Save);
  1048. }
  1049. if (!data._id) {
  1050. await localforage.setItem(localStorageName, JSON.stringify(data));
  1051. }
  1052. router.push({
  1053. path: '/preview',
  1054. query: {
  1055. r: Date.now() + '',
  1056. id: data._id,
  1057. },
  1058. });
  1059. };
  1060. const contextmenu = reactive<any>({
  1061. visible: false,
  1062. type: '',
  1063. style: {},
  1064. });
  1065. const onContextmenu = ({ e, rect }: { e: any; rect: any }) => {
  1066. contextmenu.type = '';
  1067. contextmenu.style = {
  1068. left: e.clientX + 'px',
  1069. top: e.clientY + 'px',
  1070. };
  1071. if (
  1072. meta2d.store.hoverAnchor &&
  1073. meta2d.canvas.hoverType === HoverType.LineAnchor
  1074. ) {
  1075. contextmenu.type = 'anchor';
  1076. if (document.body.clientHeight - e.clientY < 128) {
  1077. contextmenu.style = {
  1078. left: e.clientX + 'px',
  1079. bottom: '4px',
  1080. };
  1081. }
  1082. } else {
  1083. contextmenu.type = 'pen';
  1084. if (document.body.clientHeight - e.clientY < 450) {
  1085. contextmenu.style = {
  1086. left: e.clientX + 'px',
  1087. bottom: '4px',
  1088. };
  1089. }
  1090. }
  1091. if (contextmenu.type) {
  1092. contextmenu.visible = true;
  1093. } else {
  1094. contextmenu.visible = false;
  1095. }
  1096. };
  1097. const canvasClick = () => {
  1098. contextmenu.visible = false;
  1099. };
  1100. const changeContextMenuVisible = (e: boolean) => {
  1101. contextmenu.visible = e;
  1102. };
  1103. const networkColumns = ref([
  1104. {
  1105. colKey: 'name',
  1106. title: '名称',
  1107. ellipsis: true,
  1108. width: 160,
  1109. },
  1110. {
  1111. colKey: 'protocol',
  1112. title: '通信方式',
  1113. width: 120,
  1114. },
  1115. {
  1116. colKey: 'url',
  1117. title: 'URL地址',
  1118. ellipsis: true,
  1119. },
  1120. { colKey: 'actions', title: '操作', width: 100 },
  1121. ]);
  1122. const onShowDataDialog = async () => {
  1123. dataDialog.input = '';
  1124. dataDialog.networks = meta2d.store.data.networks || [];
  1125. // @ts-ignore
  1126. dataDialog.dataset = meta2d.store.data.dataset || {};
  1127. dataDialog.datasetId = dataDialog.dataset.id;
  1128. // @ts-ignore
  1129. dataDialog.enableMock = meta2d.store.data.enableMock;
  1130. dataDialog.networkList = [];
  1131. dataDialog.datasetList = [];
  1132. dataDialog.editNetwork = false;
  1133. dataDialog.save = true;
  1134. dataDialog.show = true;
  1135. getNetworks();
  1136. await getDatasets();
  1137. onSelDataset(true);
  1138. };
  1139. const onFinishDataDialog = () => {
  1140. dataDialog.show = false;
  1141. meta2d.connectNetwork();
  1142. };
  1143. const onChangeMock = () => {
  1144. // @ts-ignore
  1145. meta2d.store.data.enableMock = dataDialog.enableMock;
  1146. };
  1147. const onSelectNetWork = (item: any) => {
  1148. const network: any = dataDialog.networks.find(
  1149. (elem: any) => item.id === elem.id
  1150. );
  1151. if (!network) {
  1152. dataDialog.networks.push(item);
  1153. meta2d.store.data.networks = dataDialog.networks;
  1154. meta2d.connectNetwork();
  1155. setDot(true);
  1156. }
  1157. dataDialog.popupVisible = false;
  1158. };
  1159. const onDelNetWork = async (item: any, i: number) => {
  1160. const ret: any = await axios.post(`/api/data/datasources/delete`, {
  1161. id: item._id || item.id,
  1162. });
  1163. if (ret) {
  1164. dataDialog.networkList.splice(i, 1);
  1165. }
  1166. };
  1167. const onInputNetwork = () => {
  1168. debounce(getNetworks, 300);
  1169. };
  1170. // 请求我的实时数据
  1171. const getNetworks = async () => {
  1172. const ret: any = await axios.post(
  1173. `/api/data/datasources/list`,
  1174. {
  1175. q: {
  1176. name: dataDialog.input,
  1177. },
  1178. query: {
  1179. type: 'subscribe',
  1180. },
  1181. projection: { updatedAt: 0 },
  1182. },
  1183. {
  1184. params: {
  1185. current: 1,
  1186. pageSize: 10,
  1187. },
  1188. }
  1189. );
  1190. if (ret?.list) {
  1191. for (const item of ret.list) {
  1192. item.id = item.id || item._id;
  1193. }
  1194. dataDialog.networkList = ret.list;
  1195. }
  1196. };
  1197. const onInputDatasets = (name: string) => {
  1198. debounce(getDatasets, 300, name);
  1199. };
  1200. // 请求我的数据集
  1201. const getDatasets = async (name?: string) => {
  1202. const body: any = {
  1203. query: {
  1204. type: 'dataset',
  1205. },
  1206. projection: { updatedAt: 0 },
  1207. };
  1208. if (name) {
  1209. body.q = { name };
  1210. }
  1211. const ret: any = await axios.post(`/api/data/datasources/list`, body, {
  1212. params: {
  1213. current: 1,
  1214. pageSize: 10,
  1215. },
  1216. });
  1217. if (ret?.list) {
  1218. let found = false;
  1219. for (const item of ret.list) {
  1220. item.id = item.id || item._id;
  1221. if (dataDialog.dataset?.id === item.id) {
  1222. found = true;
  1223. }
  1224. }
  1225. if (dataDialog.dataset?.id && !found) {
  1226. ret.list.push(dataDialog.dataset);
  1227. }
  1228. dataDialog.datasetList = ret.list;
  1229. }
  1230. };
  1231. const addNetwork = () => {
  1232. dataDialog.network = {
  1233. name: '',
  1234. type: 'subscribe',
  1235. protocol: 'mqtt',
  1236. url: '',
  1237. options: {
  1238. clientId: '',
  1239. username: '',
  1240. password: '',
  1241. customClientId: false,
  1242. },
  1243. };
  1244. dataDialog.editNetwork = 1;
  1245. };
  1246. const editNetwork = (data: any) => {
  1247. dataDialog.networkBak = data;
  1248. dataDialog.network = JSON.parse(JSON.stringify(data));
  1249. dataDialog.editNetwork = 2;
  1250. };
  1251. const deleteNetwork = (index: number) => {
  1252. dataDialog.networks.splice(index, 1);
  1253. meta2d.store.data.networks = dataDialog.networks;
  1254. meta2d.connectNetwork();
  1255. setDot(true);
  1256. };
  1257. const onOkNetwork = async () => {
  1258. if (dataDialog.editNetwork === 1) {
  1259. if (dataDialog.save) {
  1260. const ret: any = await axios.post(
  1261. `/api/data/datasources/add`,
  1262. dataDialog.network
  1263. );
  1264. if (!ret) {
  1265. return;
  1266. }
  1267. ret.id = ret.id || ret._id;
  1268. dataDialog.network._id = dataDialog.network.id = ret.id;
  1269. }
  1270. dataDialog.networks.push(dataDialog.network);
  1271. dataDialog.networkList.push(dataDialog.network);
  1272. } else if (dataDialog.editNetwork === 2) {
  1273. if (dataDialog.save) {
  1274. const ret: any = await axios.post(
  1275. `/api/data/datasources/update`,
  1276. dataDialog.network
  1277. );
  1278. if (!ret) {
  1279. return;
  1280. }
  1281. }
  1282. }
  1283. meta2d.store.data.networks = dataDialog.networks;
  1284. meta2d.connectNetwork();
  1285. setDot(true);
  1286. dataDialog.editNetwork = false;
  1287. delete dataDialog.networkBak;
  1288. };
  1289. const datasetColumns = ref([
  1290. {
  1291. colKey: 'device',
  1292. title: '设备',
  1293. ellipsis: true,
  1294. },
  1295. {
  1296. colKey: 'label',
  1297. title: '数据点名称',
  1298. ellipsis: true,
  1299. },
  1300. {
  1301. colKey: 'id',
  1302. title: '数据点ID',
  1303. ellipsis: true,
  1304. },
  1305. {
  1306. colKey: 'type',
  1307. title: '类型',
  1308. ellipsis: true,
  1309. },
  1310. {
  1311. colKey: 'mock',
  1312. title: '值范围',
  1313. ellipsis: true,
  1314. },
  1315. ]);
  1316. const addDataset = () => {
  1317. dataDialog.dataset = {
  1318. name: '',
  1319. type: 'dataset',
  1320. mode: 'api',
  1321. url: '',
  1322. data: [],
  1323. };
  1324. dataDialog.editDataset = 1;
  1325. };
  1326. const editDataset = () => {
  1327. dataDialog.datasetBak = dataDialog.dataset;
  1328. dataDialog.dataset = JSON.parse(JSON.stringify(dataDialog.dataset));
  1329. dataDialog.editDataset = 2;
  1330. };
  1331. const onOkDataset = async (saveas = false) => {
  1332. if (!dataDialog.dataset.name) {
  1333. MessagePlugin.error('名称不能为空');
  1334. return;
  1335. }
  1336. const dataset = JSON.parse(JSON.stringify(dataDialog.dataset));
  1337. // 保存到我的数据源
  1338. if (saveas || dataDialog.editDataset === 1) {
  1339. delete dataset.id;
  1340. delete dataset._id;
  1341. const ret: any = await axios.post(`/api/data/datasources/add`, dataset);
  1342. if (!ret) {
  1343. return;
  1344. }
  1345. ret.id = ret.id || ret._id;
  1346. dataDialog.datasetId = ret.id;
  1347. dataset._id = dataset.id = ret.id;
  1348. dataDialog.datasetList.push(dataset);
  1349. } else {
  1350. const ret: any = await axios.post(`/api/data/datasources/update`, dataset);
  1351. if (!ret) {
  1352. return;
  1353. }
  1354. }
  1355. delete dataset.data;
  1356. // @ts-ignore
  1357. meta2d.store.data.dataset = dataset;
  1358. setDot(true);
  1359. dataDialog.editDataset = false;
  1360. delete dataDialog.datesetBak;
  1361. };
  1362. const onDelDataset = async (item: any, i: number) => {
  1363. const ret: any = await axios.post(`/api/data/datasources/delete`, {
  1364. id: item.id,
  1365. });
  1366. if (ret) {
  1367. dataDialog.datasetList.splice(i, 1);
  1368. }
  1369. };
  1370. const onSelDataset = async (init = false) => {
  1371. if (dataDialog.datasetId) {
  1372. const dataset = dataDialog.datasetList.find((item: any) => {
  1373. return item.id === dataDialog.datasetId;
  1374. });
  1375. if (!dataset) {
  1376. return;
  1377. }
  1378. if (dataset.url) {
  1379. const ret = await axios.get(dataset.url);
  1380. if (ret) {
  1381. dataset.data = ret;
  1382. }
  1383. } else {
  1384. const ret = await axios.post(`/api/data/datasources/get`, {
  1385. id: dataset.id,
  1386. });
  1387. if (ret?.data) {
  1388. dataset.data = ret.data;
  1389. }
  1390. }
  1391. dataDialog.dataset = dataset;
  1392. if (!init) {
  1393. const d = JSON.parse(JSON.stringify(dataset));
  1394. delete d.data;
  1395. // @ts-ignore
  1396. meta2d.store.data.dataset = d;
  1397. setDot(true);
  1398. }
  1399. }
  1400. };
  1401. const share = async () => {
  1402. if (!route.query.id) {
  1403. MessagePlugin.error('请先保存!');
  1404. return;
  1405. }
  1406. const ret: any = await updateCollection('le5leV', {
  1407. _id: route.query.id,
  1408. shared: !shared.value,
  1409. });
  1410. if (ret) {
  1411. shared.value = ret.shared;
  1412. }
  1413. };
  1414. let qrTimer: any;
  1415. const onEnterQrcode = () => {
  1416. if (!qrcode.visible && !qrTimer) {
  1417. qrTimer = setTimeout(() => {
  1418. qrTimer = undefined;
  1419. qrcode.visible = true;
  1420. }, 300);
  1421. }
  1422. };
  1423. const onLeaveQrcode = () => {
  1424. if (qrTimer) {
  1425. clearTimeout(qrTimer);
  1426. qrTimer = undefined;
  1427. }
  1428. };
  1429. const onShowPublish = async () => {
  1430. // @ts-ignore
  1431. publishDialog.name = meta2d.store.data.name;
  1432. publishDialog.status = '';
  1433. publishDialog.tips = '';
  1434. publishDialog.id = route.query.id + '';
  1435. publishDialog.show = true;
  1436. const ret: any = await axios.post(`/api/domain/get`, {
  1437. id: publishDialog.id,
  1438. });
  1439. if (ret) {
  1440. if (ret.expired) {
  1441. const expired = new Date(ret.expired);
  1442. if (expired > new Date()) {
  1443. ret.isExpired = false;
  1444. } else if (expired > new Date('2023-01-17T08:00:00+08:00')) {
  1445. ret.isExpired = true;
  1446. } else {
  1447. ret.expired = undefined;
  1448. }
  1449. if (ret.expired) {
  1450. ret.expired = dayjs(ret.expired).format('YYYY-MM-DD HH:mm:ss');
  1451. }
  1452. }
  1453. publishDialog.data = ret;
  1454. makePublishQrcode();
  1455. }
  1456. };
  1457. const refreshSubdomain = async () => {
  1458. publishDialog.data.subDomain = s8();
  1459. onChangeSubdomain();
  1460. };
  1461. const onChangeSubdomain = async () => {
  1462. if (!publishDialog.data.subDomain) {
  1463. publishDialog.status = 'error';
  1464. publishDialog.tips = '请填写子域名';
  1465. }
  1466. const ret: any = await axios.post(`/api/domain/exists`, {
  1467. subDomain: publishDialog.data.subDomain,
  1468. });
  1469. if (ret && ret.id) {
  1470. publishDialog.status = 'error';
  1471. publishDialog.tips = '已经存在相同子域名';
  1472. } else {
  1473. publishDialog.status = '';
  1474. publishDialog.tips = '';
  1475. }
  1476. if (
  1477. !publishDialog.data.domain ||
  1478. publishDialog.data.domain.indexOf('.v.le5le.com') >= 0
  1479. ) {
  1480. publishDialog.data.domain = publishDialog.data.subDomain + '.v.le5le.com';
  1481. }
  1482. makePublishQrcode();
  1483. };
  1484. const onPublish = async () => {
  1485. if (publishDialog.status) {
  1486. return;
  1487. }
  1488. if (!publishDialog.data.subDomain) {
  1489. publishDialog.status = 'error';
  1490. publishDialog.tips = '请填写子域名';
  1491. }
  1492. if (!publishDialog.data.domain) {
  1493. publishDialog.data.domain = publishDialog.data.subDomain + '.v.le5le.com';
  1494. }
  1495. const ret: any = await axios.post(`/api/domain/set`, {
  1496. id: route.query.id,
  1497. subDomain: publishDialog.data.subDomain,
  1498. domain: publishDialog.data.domain,
  1499. });
  1500. if (ret) {
  1501. if (ret.expired) {
  1502. const expired = new Date(ret.expired);
  1503. if (expired > new Date()) {
  1504. ret.isExpired = false;
  1505. } else if (expired > new Date('2023-01-17T08:00:00+08:00')) {
  1506. ret.isExpired = true;
  1507. } else {
  1508. ret.expired = undefined;
  1509. }
  1510. if (ret.expired) {
  1511. ret.expired = dayjs(ret.expired).format('YYYY-MM-DD HH:mm:ss');
  1512. }
  1513. }
  1514. publishDialog.data = ret;
  1515. makePublishQrcode();
  1516. }
  1517. };
  1518. const makePublishQrcode = async () => {
  1519. const qr: any = await QRCode.toDataURL(`http://${publishDialog.data.domain}`);
  1520. publishDialog.url = qr;
  1521. };
  1522. const onSuccessChargeCloud = () => {
  1523. publishChargeDialog.show = false;
  1524. onShowPublish();
  1525. };
  1526. </script>
  1527. <style lang="postcss" scoped>
  1528. .meta2d {
  1529. display: flex;
  1530. flex-direction: column;
  1531. background-color: var(--color-background-editor);
  1532. border-left: 1px solid var(--color-border);
  1533. .tools {
  1534. display: flex;
  1535. font-size: 12px;
  1536. background-color: var(--color-background);
  1537. height: 40px;
  1538. flex-shrink: 0;
  1539. padding: 0 12px;
  1540. z-index: 2;
  1541. a {
  1542. display: flex;
  1543. align-items: center;
  1544. height: 100%;
  1545. padding: 0 10px;
  1546. color: var(--color);
  1547. text-decoration: none;
  1548. .l-icon {
  1549. width: 16px;
  1550. height: 16px;
  1551. }
  1552. &:hover {
  1553. color: var(--color-primary);
  1554. }
  1555. }
  1556. .t-icon {
  1557. font-size: 16px;
  1558. }
  1559. }
  1560. #meta2d {
  1561. border-top: 1px solid var(--color-background-input);
  1562. height: calc(100vh - 81px);
  1563. z-index: 1;
  1564. :deep(.meta2d-map) {
  1565. background: var(--color-background);
  1566. }
  1567. }
  1568. }
  1569. </style>