View.vue 57 KB

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