View.vue 52 KB

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