View.vue 49 KB

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