View.vue 58 KB

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