PenProps.vue 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532
  1. <template>
  2. <div class="props">
  3. <t-tabs v-model="data.tab">
  4. <t-tab-panel :value="1" label="外观">
  5. <t-space direction="vertical" class="py-16 w-full">
  6. <div class="form-item px-12">
  7. <label style="width: 50px">ID</label>
  8. <t-input
  9. class="w-full"
  10. placeholder="ID"
  11. :value="data.pen.id"
  12. @change="changeID($event)"
  13. />
  14. </div>
  15. <div class="form-item px-12" style="margin-top: -12px">
  16. <label style="width: 50px">名称</label>
  17. <!-- <t-input
  18. class="w-full"
  19. placeholder="名称"
  20. disabled
  21. v-model.number="data.pen.name"
  22. @change="changeValue('name')"
  23. /> -->
  24. <div style="padding-left: 8px; line-height: 30px">
  25. {{ data.pen.name }}
  26. </div>
  27. </div>
  28. <div class="form-item px-12" style="margin-top: -12px">
  29. <label style="width: 50px">分组</label>
  30. <t-select-input
  31. v-model:inputValue="data.inputTag"
  32. :value="data.pen.tags"
  33. v-model:popupVisible="data.tagPopupVisible"
  34. allow-input
  35. placeholder="请输入或选择分组"
  36. multiple
  37. @tag-change="onChangeInputTag"
  38. @focus="data.tagPopupVisible = true"
  39. @blur="data.tagPopupVisible = false"
  40. :tag-input-props="{ excessTagsDisplayType: 'scroll' }"
  41. >
  42. <template #panel>
  43. <ul style="padding: 8px 12px">
  44. <li
  45. v-for="item in data.groups"
  46. :key="item"
  47. @click="onSelectTag(item)"
  48. >
  49. {{ item }}
  50. </li>
  51. </ul>
  52. </template>
  53. </t-select-input>
  54. </div>
  55. <div class="form-item px-12" style="margin-top: -12px">
  56. <label style="width: 50px">模板</label>
  57. <t-switch
  58. class="mt-8 ml-8"
  59. v-model="data.pen.template"
  60. size="small"
  61. @change="changeValue('template')"
  62. />
  63. </div>
  64. <t-divider style="margin: -8px 0" />
  65. <div style="margin: 0 16px 16px 16px">
  66. <t-space direction="vertical" size="small" class="w-full">
  67. <div style="color: var(--color); margin-bottom: 2px">
  68. 大屏对齐
  69. </div>
  70. <div class="icons">
  71. <t-tooltip
  72. v-for="item in aligns"
  73. :content="item.label"
  74. placement="top"
  75. >
  76. <svg
  77. class="l-icon btn"
  78. aria-hidden="true"
  79. @click="align(item.value)"
  80. >
  81. <use :xlink:href="item.icon"></use>
  82. </svg>
  83. </t-tooltip>
  84. </div>
  85. </t-space>
  86. </div>
  87. <t-divider style="margin: -8px 0" />
  88. <div class="form-item" style="margin-top: -12px">
  89. <t-input
  90. class="ml-4"
  91. label="X"
  92. placeholder="X"
  93. v-model.number="data.rect.x"
  94. style="width: 80px"
  95. :format="decimalPlaces"
  96. @change="changeRectValue('x')"
  97. />
  98. <t-icon name="link" class="hidden ml-4" />
  99. <t-input
  100. class="ml-4"
  101. label="Y"
  102. placeholder="Y"
  103. v-model.number="data.rect.y"
  104. style="width: 80px"
  105. :format="decimalPlaces"
  106. @change="changeRectValue('y')"
  107. />
  108. <t-input
  109. class="ml-16"
  110. v-model.number="data.pen.rotate"
  111. placeholder="旋转"
  112. style="width: 80px"
  113. :format="decimalRound"
  114. @change="changeValue('rotate')"
  115. >
  116. <template #prefix-icon>
  117. <svg class="l-icon" aria-hidden="true">
  118. <use xlink:href="#l-rotate"></use>
  119. </svg>
  120. </template>
  121. </t-input>
  122. </div>
  123. <div class="form-item hover-icons" style="margin-top: -12px">
  124. <t-input
  125. class="ml-4"
  126. label="W"
  127. v-model.number="data.rect.width"
  128. placeholder="宽"
  129. min="1"
  130. style="width: 80px"
  131. :format="decimalPlaces"
  132. @change="changeRectValue('width')"
  133. />
  134. <t-tooltip v-if="data.pen.ratio" content="固定比例" placement="top">
  135. <t-icon
  136. name="link"
  137. class="ml-4 hover"
  138. @click="data.pen.ratio = !data.pen.ratio"
  139. />
  140. </t-tooltip>
  141. <t-tooltip v-else content="不固定比例" placement="top">
  142. <t-icon
  143. name="link-unlink"
  144. class="ml-4 hover icon"
  145. @click="data.pen.ratio = !data.pen.ratio"
  146. />
  147. </t-tooltip>
  148. <t-input
  149. class="ml-4"
  150. label="H"
  151. placeholder="高"
  152. v-model.number="data.rect.height"
  153. min="1"
  154. style="width: 80px"
  155. :format="decimalPlaces"
  156. @change="changeRectValue('height')"
  157. />
  158. <t-input
  159. class="ml-16"
  160. v-model.number="data.pen.borderRadius"
  161. placeholder="圆角"
  162. style="width: 80px"
  163. @change="changeValue('borderRadius')"
  164. >
  165. <template #prefix-icon>
  166. <svg class="l-icon" aria-hidden="true">
  167. <use xlink:href="#l-border-radius"></use>
  168. </svg>
  169. </template>
  170. </t-input>
  171. </div>
  172. <t-divider style="margin: -8px 0" />
  173. <div class="form-item px-16" style="margin-top: -12px">
  174. <label>不透明度</label>
  175. <t-slider
  176. v-model="data.pen.globalAlpha"
  177. :min="0"
  178. :max="1"
  179. :step="0.01"
  180. @change="changeValue('globalAlpha')"
  181. />
  182. <span class="ml-16" style="width: 50px; line-height: 30px">
  183. {{ data.pen.globalAlpha }}
  184. </span>
  185. </div>
  186. <t-collapse
  187. :defaultValue="['1', '2', '3', '4', '5']"
  188. expandIconPlacement="right"
  189. :borderless="true"
  190. >
  191. <t-collapse-panel
  192. v-if="data.pen.props.look !== false"
  193. value="1"
  194. header="外观"
  195. >
  196. <t-space direction="vertical" size="small" class="w-full">
  197. <div class="form-item">
  198. <t-color-picker
  199. class="simple mt-8 mr-4"
  200. format="CSS"
  201. :enable-alpha="true"
  202. :recent-colors="null"
  203. :swatch-colors="defaultPureColor"
  204. :color-modes="['monochrome']"
  205. :show-primary-color-preview="false"
  206. :clearable="true"
  207. v-model="data.pen.color"
  208. @change="changeValue('color')"
  209. />
  210. <label style="width: 64px">前景颜色</label>
  211. <t-color-picker
  212. class="simple mt-8 mr-4"
  213. format="CSS"
  214. :enable-alpha="true"
  215. :recent-colors="null"
  216. :swatch-colors="defaultPureColor"
  217. :color-modes="['monochrome']"
  218. :show-primary-color-preview="false"
  219. v-model="data.pen.hoverColor"
  220. @change="changeValue('hoverColor')"
  221. />
  222. <label style="width: 64px">悬停颜色</label>
  223. <t-color-picker
  224. class="simple mt-8 mr-4"
  225. format="CSS"
  226. :enable-alpha="true"
  227. :recent-colors="null"
  228. :swatch-colors="defaultPureColor"
  229. :color-modes="['monochrome']"
  230. :show-primary-color-preview="false"
  231. v-model="data.pen.activeColor"
  232. @change="changeValue('activeColor')"
  233. />
  234. <label style="width: 64px">选中颜色</label>
  235. </div>
  236. <div class="form-item">
  237. <label style="width: 32px">线条 </label>
  238. <t-select
  239. v-model="data.pen.dash"
  240. placeholder="线条样式"
  241. @change="changeValue('dash')"
  242. style="width: 80px"
  243. >
  244. <template #valueDisplay="{ value }">
  245. <svg
  246. xmlns="http://www.w3.org/2000/svg"
  247. version="1.1"
  248. style="width: 100%; height: 20px"
  249. >
  250. <g fill="none" stroke="var(--color)" stroke-width="1">
  251. <path v-if="value === 0" d="M0 9 l85 0" />
  252. <path
  253. v-else-if="value === 1"
  254. stroke-dasharray="5 5"
  255. d="M0 9 l85 0"
  256. />
  257. <path
  258. v-else-if="value === 2"
  259. stroke-dasharray="10 10"
  260. d="M0 9 l85 0"
  261. />
  262. <path
  263. v-else-if="value === 3"
  264. stroke-dasharray="10 10 2 10"
  265. d="M0 9 l85 0"
  266. />
  267. </g>
  268. </svg>
  269. </template>
  270. <t-option :key="0" :value="0">
  271. <svg
  272. xmlns="http://www.w3.org/2000/svg"
  273. version="1.1"
  274. style="width: 80px; height: 14px"
  275. >
  276. <g fill="none" stroke="var(--color)" stroke-width="1">
  277. <path d="M0 9 l85 0" />
  278. </g>
  279. </svg>
  280. </t-option>
  281. <t-option :key="1" :value="1">
  282. <svg
  283. xmlns="http://www.w3.org/2000/svg"
  284. version="1.1"
  285. style="width: 80px; height: 14px"
  286. >
  287. <g fill="none" stroke="var(--color)" stroke-width="1">
  288. <path stroke-dasharray="5 5" d="M0 9 l85 0" />
  289. </g>
  290. </svg>
  291. </t-option>
  292. <t-option :key="2" :value="2">
  293. <svg
  294. xmlns="http://www.w3.org/2000/svg"
  295. version="1.1"
  296. style="width: 80px; height: 14px"
  297. >
  298. <g fill="none" stroke="var(--color)" stroke-width="1">
  299. <path stroke-dasharray="10 10" d="M0 9 l85 0" />
  300. </g>
  301. </svg>
  302. </t-option>
  303. <t-option :key="3" :value="3">
  304. <svg
  305. xmlns="http://www.w3.org/2000/svg"
  306. version="1.1"
  307. style="width: 80px; height: 14px"
  308. >
  309. <g fill="none" stroke="var(--color)" stroke-width="1">
  310. <path stroke-dasharray="10 10 2 10" d="M0 9 l85 0" />
  311. </g>
  312. </svg>
  313. </t-option>
  314. </t-select>
  315. <t-input-number
  316. theme="normal"
  317. placeholder="线条宽度"
  318. v-model="data.pen.lineWidth"
  319. :min="0"
  320. :decimalPlaces="0"
  321. @change="changeValue('lineWidth')"
  322. class="ml-4"
  323. style="width: 40px"
  324. />
  325. <t-tooltip content="线条渐变" placement="top">
  326. <div class="flex middle ml-8">
  327. <t-checkbox
  328. v-model="data.pen.strokeType"
  329. @change="changeValue('strokeType')"
  330. style="width: 22px"
  331. />
  332. <t-color-picker
  333. v-if="data.pen.strokeType"
  334. class="simple mr-4"
  335. format="CSS"
  336. :swatch-colors="defaultGradientColor"
  337. :color-modes="['linear-gradient']"
  338. :show-primary-color-preview="false"
  339. :recent-colors="null"
  340. :enableAlpha="true"
  341. v-model="data.pen.lineGradientColors"
  342. @change="changeValue('lineGradientColors')"
  343. placeholder="无"
  344. />
  345. </div>
  346. </t-tooltip>
  347. </div>
  348. <div class="flex" style="margin-left: 40px">
  349. <div class="flex column middle">
  350. <t-radio-group
  351. size="small"
  352. v-model="data.pen.lineCap"
  353. default-value="butt"
  354. @change="changeValue('lineCap')"
  355. >
  356. <t-radio-button value="butt">
  357. <t-tooltip content="默认" placement="top">
  358. <svg class="l-icon" aria-hidden="true">
  359. <use xlink:href="#l-duandian1"></use>
  360. </svg>
  361. </t-tooltip>
  362. </t-radio-button>
  363. <t-radio-button value="round">
  364. <t-tooltip content="圆形" placement="top">
  365. <svg class="l-icon" aria-hidden="true">
  366. <use xlink:href="#l-duandian2"></use>
  367. </svg>
  368. </t-tooltip>
  369. </t-radio-button>
  370. <t-radio-button value="square">
  371. <t-tooltip content="方形" placement="top">
  372. <svg class="l-icon" aria-hidden="true">
  373. <use xlink:href="#l-duandian3"></use>
  374. </svg>
  375. </t-tooltip>
  376. </t-radio-button>
  377. </t-radio-group>
  378. <div class="mt-4" style="font-size: 12px">末端样式</div>
  379. </div>
  380. <div class="flex column middle ml-16">
  381. <t-radio-group
  382. size="small"
  383. v-model="data.pen.lineJoin"
  384. default-value="miter"
  385. @change="changeValue('lineJoin')"
  386. >
  387. <t-radio-button value="miter">
  388. <t-tooltip content="默认" placement="top">
  389. <svg class="l-icon" aria-hidden="true">
  390. <use xlink:href="#l-jiedian1"></use>
  391. </svg>
  392. </t-tooltip>
  393. </t-radio-button>
  394. <t-radio-button value="round">
  395. <t-tooltip content="圆形" placement="top">
  396. <svg class="l-icon" aria-hidden="true">
  397. <use xlink:href="#l-jiedian2"></use>
  398. </svg>
  399. </t-tooltip>
  400. </t-radio-button>
  401. <t-radio-button value="bevel">
  402. <t-tooltip content="斜角" placement="top">
  403. <svg class="l-icon" aria-hidden="true">
  404. <use xlink:href="#l-jiedian3"></use>
  405. </svg>
  406. </t-tooltip>
  407. </t-radio-button>
  408. </t-radio-group>
  409. <div class="mt-4" style="font-size: 12px">连接样式</div>
  410. </div>
  411. </div>
  412. <div class="form-item">
  413. <label style="width: 32px">背景</label>
  414. <div class="ml-8">
  415. <t-radio-group
  416. size="small"
  417. v-model="data.pen.bkType"
  418. :default-value="0"
  419. @change="changeValue('bkType')"
  420. >
  421. <t-radio-button :value="0"> 纯色 </t-radio-button>
  422. <t-radio-button :value="1"> 线性渐变 </t-radio-button>
  423. <t-radio-button :value="2"> 径向渐变 </t-radio-button>
  424. </t-radio-group>
  425. <div v-if="data.pen.bkType === 0" class="mt-8 -ml-8">
  426. <t-color-picker
  427. class="w-full"
  428. format="CSS"
  429. :swatch-colors="defaultPureColor"
  430. :color-modes="['monochrome']"
  431. :recent-colors="null"
  432. :enable-alpha="true"
  433. :show-primary-color-preview="false"
  434. v-model="data.pen.background"
  435. @change="changeValue('background')"
  436. />
  437. </div>
  438. <div
  439. v-else-if="data.pen.bkType === 1"
  440. class="mt-8 -ml-8"
  441. style="width: 200px"
  442. >
  443. <t-color-picker
  444. class="w-full"
  445. format="CSS"
  446. :enable-alpha="true"
  447. :recent-colors="null"
  448. :swatch-colors="defaultGradientColor"
  449. :color-modes="['linear-gradient']"
  450. :show-primary-color-preview="false"
  451. v-model="data.pen.gradientColors"
  452. @change="changeValue('gradientColors')"
  453. />
  454. </div>
  455. <div
  456. v-else-if="data.pen.bkType === 2"
  457. class="mt-8 flex middle"
  458. >
  459. <t-color-picker
  460. class="simple"
  461. format="CSS"
  462. :enable-alpha="true"
  463. :recent-colors="null"
  464. :swatch-colors="defaultGradientColor"
  465. :color-modes="['linear-gradient']"
  466. :show-primary-color-preview="false"
  467. v-model="data.pen.gradientColors"
  468. @change="changeValue('gradientColors')"
  469. />
  470. <t-input-number
  471. theme="column"
  472. placeholder="渐变半径"
  473. v-model="data.pen.gradientRadius"
  474. :min="0"
  475. :max="1"
  476. :step="0.1"
  477. @change="changeValue('gradientRadius')"
  478. class="ml-8"
  479. style="width: 100px"
  480. />
  481. </div>
  482. </div>
  483. </div>
  484. <div class="form-item">
  485. <label style="width: 32px">阴影 </label>
  486. <div class="flex middle ml-8">
  487. <t-checkbox
  488. v-model="data.pen.shadow"
  489. @change="changeValue('shadow')"
  490. style="width: 22px"
  491. />
  492. <t-color-picker
  493. v-if="data.pen.shadow"
  494. class="simple"
  495. format="CSS"
  496. :enable-alpha="true"
  497. :recent-colors="null"
  498. :swatch-colors="defaultPureColor"
  499. :color-modes="['monochrome']"
  500. :show-primary-color-preview="false"
  501. v-model="data.pen.shadowColor"
  502. @change="changeValue('shadowColor')"
  503. />
  504. </div>
  505. <label
  506. v-if="data.pen.shadow"
  507. style="width: 50px; margin-left: 25px"
  508. >文字阴影
  509. </label>
  510. <div v-if="data.pen.shadow" class="flex middle ml-8">
  511. <t-checkbox
  512. v-model="data.pen.textHasShadow"
  513. @change="changeValue('textHasShadow')"
  514. style="width: 22px"
  515. />
  516. </div>
  517. </div>
  518. <div class="form-item" v-if="data.pen.shadow">
  519. <label style="width: 28px"></label>
  520. <div class="flex" style="margin-top: -8px">
  521. <t-input
  522. class="ml-4"
  523. label="X"
  524. placeholder="0"
  525. v-model.number="data.pen.shadowOffsetX"
  526. style="width: 60px"
  527. @change="changeValue('shadowOffsetX')"
  528. title="X偏移"
  529. />
  530. <t-input
  531. class="ml-4"
  532. label="Y"
  533. placeholder="0"
  534. v-model.number="data.pen.shadowOffsetY"
  535. style="width: 60px"
  536. @change="changeValue('shadowOffsetY')"
  537. title="Y偏移"
  538. />
  539. <t-input
  540. class="ml-4"
  541. label="模糊"
  542. placeholder="0"
  543. v-model.number="data.pen.shadowBlur"
  544. style="width: 64px"
  545. @change="changeValue('shadowBlur')"
  546. title="模糊大小"
  547. />
  548. </div>
  549. </div>
  550. </t-space>
  551. </t-collapse-panel>
  552. <t-collapse-panel
  553. v-if="data.pen.props.text"
  554. value="2"
  555. header="文字"
  556. >
  557. <t-space direction="vertical" size="small" class="w-full">
  558. <div class="form-item">
  559. <div class="flex middle" style="margin-left: -10px">
  560. <t-select-input
  561. :value="data.pen.fontFamily"
  562. :popup-visible="data.fontFamilyPopupVisible"
  563. placeholder="字体名"
  564. allow-input
  565. style="width: 170px"
  566. @change="changeValue('fontFamily')"
  567. @enter="changeValue('fontFamily')"
  568. @blur="changeValue('fontFamily')"
  569. @popup-visible-change="onFontPopupVisible"
  570. :popup-props="{
  571. overlayInnerStyle: { width: 'auto' },
  572. }"
  573. >
  574. <template #panel>
  575. <ul style="padding: 12px">
  576. <li
  577. v-for="item in fonts"
  578. :key="item"
  579. @click="onFontFamily(item)"
  580. >
  581. {{ item }}
  582. </li>
  583. </ul>
  584. </template>
  585. <template #suffixIcon>
  586. <t-icon name="chevron-down" />
  587. </template>
  588. </t-select-input>
  589. <t-input
  590. class="ml-8"
  591. placeholder="字体大小"
  592. v-model.number="data.pen.fontSize"
  593. style="width: 80px"
  594. :format="decimalRound"
  595. @change="changeValue('fontSize')"
  596. />
  597. </div>
  598. </div>
  599. <div class="flex middle">
  600. <t-radio-group
  601. size="small"
  602. v-model="data.pen.textAlign"
  603. default-value="center"
  604. @change="changeValue('textAlign')"
  605. >
  606. <t-radio-button value="left">
  607. <t-tooltip content="居左" placement="top">
  608. <t-icon name="format-vertical-align-left" />
  609. </t-tooltip>
  610. </t-radio-button>
  611. <t-radio-button value="center">
  612. <t-tooltip content="居中" placement="top">
  613. <t-icon name="format-vertical-align-center" />
  614. </t-tooltip>
  615. </t-radio-button>
  616. <t-radio-button value="right">
  617. <t-tooltip content="居右" placement="top">
  618. <t-icon name="format-vertical-align-right" />
  619. </t-tooltip>
  620. </t-radio-button>
  621. </t-radio-group>
  622. <t-radio-group
  623. class="ml-8"
  624. size="small"
  625. v-model="data.pen.textBaseline"
  626. default-value="top"
  627. @change="changeValue('textBaseline')"
  628. >
  629. <t-radio-button value="top">
  630. <t-tooltip content="顶部对齐" placement="top">
  631. <t-icon name="format-horizontal-align-top" />
  632. </t-tooltip>
  633. </t-radio-button>
  634. <t-radio-button value="middle">
  635. <t-tooltip content="垂直居中" placement="middle">
  636. <t-icon name="format-horizontal-align-center" />
  637. </t-tooltip>
  638. </t-radio-button>
  639. <t-radio-button value="bottom">
  640. <t-tooltip content="底部对齐" placement="top">
  641. <t-icon name="format-horizontal-align-bottom" />
  642. </t-tooltip>
  643. </t-radio-button>
  644. </t-radio-group>
  645. <t-button
  646. :class="{ active: data.pen.fontWeight === 'bold' }"
  647. class="ml-8 icon"
  648. shape="rectangle"
  649. variant="text"
  650. @click="
  651. data.pen.fontWeight === 'bold'
  652. ? (data.pen.fontWeight = 'normal')
  653. : (data.pen.fontWeight = 'bold');
  654. changeValue('fontWeight');
  655. "
  656. >
  657. B
  658. </t-button>
  659. <t-button
  660. :class="{ active: data.pen.fontStyle === 'italic' }"
  661. class="ml-4 icon"
  662. shape="rectangle"
  663. variant="text"
  664. @click="
  665. data.pen.fontStyle === 'italic'
  666. ? (data.pen.fontStyle = 'normal')
  667. : (data.pen.fontStyle = 'italic');
  668. changeValue('fontStyle');
  669. "
  670. style="font-style: italic; font-family: serif"
  671. >I</t-button
  672. >
  673. </div>
  674. <div class="form-item">
  675. <t-color-picker
  676. class="simple mt-8 mr-4"
  677. format="CSS"
  678. :enable-alpha="true"
  679. :recent-colors="null"
  680. :swatch-colors="defaultPureColor"
  681. :color-modes="['monochrome']"
  682. :show-primary-color-preview="false"
  683. v-model="data.pen.textColor"
  684. @change="changeValue('textColor')"
  685. />
  686. <label style="width: 44px">前景</label>
  687. <t-color-picker
  688. class="simple mt-8 mr-4"
  689. format="CSS"
  690. :enable-alpha="true"
  691. :recent-colors="null"
  692. :swatch-colors="defaultPureColor"
  693. :color-modes="['monochrome']"
  694. :show-primary-color-preview="false"
  695. v-model="data.pen.textBackground"
  696. @change="changeValue('textBackground')"
  697. />
  698. <label style="width: 44px">背景</label>
  699. <t-color-picker
  700. class="simple mt-8 mr-4"
  701. format="CSS"
  702. :enable-alpha="true"
  703. :recent-colors="null"
  704. :swatch-colors="defaultPureColor"
  705. :color-modes="['monochrome']"
  706. :show-primary-color-preview="false"
  707. v-model="data.pen.hoverTextColor"
  708. @change="changeValue('hoverTextColor')"
  709. />
  710. <label style="width: 44px">悬停</label>
  711. <t-color-picker
  712. class="simple mt-8 mr-4"
  713. format="CSS"
  714. :enable-alpha="true"
  715. :recent-colors="null"
  716. :swatch-colors="defaultPureColor"
  717. :color-modes="['monochrome']"
  718. :show-primary-color-preview="false"
  719. v-model="data.pen.activeTextColor"
  720. @change="changeValue('activeTextColor')"
  721. />
  722. <label style="width: 44px">选中</label>
  723. </div>
  724. <div class="form-item">
  725. <t-checkbox
  726. v-model="data.pen.whiteSpace"
  727. @change="changeValue('whiteSpace')"
  728. style="width: 64px"
  729. >
  730. 换行
  731. </t-checkbox>
  732. <t-checkbox
  733. v-model="data.pen.ellipsis"
  734. @change="changeValue('ellipsis')"
  735. style="width: 68px"
  736. >
  737. 省略号
  738. </t-checkbox>
  739. <t-tooltip content="行高">
  740. <t-input
  741. placeholder="行高"
  742. v-model.number="data.pen.lineHeight"
  743. style="width: 40px"
  744. @change="changeValue('lineHeight')"
  745. />
  746. </t-tooltip>
  747. <t-tooltip content="显示时保留小数位数">
  748. <t-input
  749. class="ml-4"
  750. placeholder="小数"
  751. v-model.number="data.pen.keepDecimal"
  752. style="width: 60px"
  753. @change="changeValue('keepDecimal')"
  754. />
  755. </t-tooltip>
  756. </div>
  757. <div class="form-item" style="margin-top: -4px">
  758. <t-tooltip content="水平偏移">
  759. <t-input
  760. placeholder="X"
  761. v-model.number="data.pen.textLeft"
  762. style="width: 60px; margin-left: -8px"
  763. @change="changeValue('textLeft')"
  764. />
  765. </t-tooltip>
  766. <t-tooltip content="垂直偏移">
  767. <t-input
  768. class="ml-4"
  769. placeholder="Y"
  770. v-model.number="data.pen.textTop"
  771. style="width: 60px"
  772. @change="changeValue('textTop')"
  773. />
  774. </t-tooltip>
  775. <t-tooltip content="宽">
  776. <t-input
  777. class="ml-4"
  778. placeholder="宽"
  779. v-model.number="data.pen.textWidth"
  780. style="width: 60px"
  781. @change="changeValue('textWidth')"
  782. />
  783. </t-tooltip>
  784. <t-tooltip content="高">
  785. <t-input
  786. class="ml-4"
  787. placeholder="高"
  788. v-model.number="data.pen.textHeight"
  789. style="width: 60px"
  790. @change="changeValue('textHeight')"
  791. />
  792. </t-tooltip>
  793. </div>
  794. <div class="flex middle">
  795. <t-checkbox
  796. v-model="data.pen.disableInput"
  797. @change="changeValue('disableInput')"
  798. style="width: 64px"
  799. >
  800. 只读
  801. </t-checkbox>
  802. <t-checkbox
  803. v-model="data.pen.hiddenText"
  804. @change="changeValue('hiddenText')"
  805. style="width: 90px"
  806. >
  807. 隐藏文字
  808. </t-checkbox>
  809. <t-checkbox
  810. v-model="data.pen.textAutoAdjust"
  811. @change="changeValue('textAutoAdjust')"
  812. style="width: 90px"
  813. >
  814. 自动调整
  815. </t-checkbox>
  816. </div>
  817. </t-space>
  818. </t-collapse-panel>
  819. <t-collapse-panel
  820. v-if="data.pen.props.image"
  821. value="3"
  822. header="图片"
  823. >
  824. <t-space direction="vertical" size="small" class="w-full">
  825. <div>
  826. <t-upload
  827. ref="uploadRef"
  828. v-model="data.images"
  829. action="/api/image/upload"
  830. theme="image"
  831. accept="image/*"
  832. :headers="headers"
  833. :data="updataData"
  834. :before-upload="beforeUpload"
  835. draggable
  836. @success="fileSuccessed"
  837. @remove="fileRemoved"
  838. >
  839. <template #fileListDisplay>
  840. <div style="z-index: 20">
  841. <a class="mr-4" @click="upload"> 点击上传 </a>
  842. / 拖拽图片到此区域
  843. </div>
  844. </template>
  845. </t-upload>
  846. </div>
  847. <div class="form-item hover-icons" style="margin-left: -12px">
  848. <t-input
  849. class="ml-4"
  850. label="W"
  851. v-model.number="data.pen.iconWidth"
  852. placeholder="自适应"
  853. min="1"
  854. style="width: 80px"
  855. :format="decimalPlaces"
  856. @change="changeValue('iconWidth')"
  857. />
  858. <t-tooltip
  859. v-if="data.pen.imageRatio"
  860. content="固定比例"
  861. placement="top"
  862. >
  863. <t-icon
  864. name="link"
  865. class="ml-4 hover"
  866. @click="data.pen.imageRatio = !data.pen.imageRatio"
  867. />
  868. </t-tooltip>
  869. <t-tooltip v-else content="不固定比例" placement="top">
  870. <t-icon
  871. name="link-unlink"
  872. class="ml-4 hover icon"
  873. @click="data.pen.imageRatio = !data.pen.imageRatio"
  874. />
  875. </t-tooltip>
  876. <t-input
  877. class="ml-4"
  878. label="H"
  879. placeholder="自适应"
  880. v-model.number="data.pen.iconHeight"
  881. min="1"
  882. style="width: 80px"
  883. :format="decimalPlaces"
  884. @change="changeValue('iconHeight')"
  885. />
  886. <t-checkbox
  887. class="ml-8"
  888. v-model="data.pen.isBottom"
  889. @change="changeValue('isBottom')"
  890. >
  891. 置底
  892. </t-checkbox>
  893. </div>
  894. <div class="flex">
  895. <label style="width: 30px; color: var(--color)">Url:</label>
  896. {{ data.pen.image }}
  897. </div>
  898. </t-space>
  899. </t-collapse-panel>
  900. <t-collapse-panel
  901. v-if="data.pen.props.icon"
  902. value="4"
  903. header="图标"
  904. >
  905. <t-space direction="vertical" size="small" class="w-full">
  906. <div class="form-item">
  907. <label style="width: 32px">图标 </label>
  908. <i
  909. class="ml-8"
  910. :class="data.pen.iconFamily"
  911. style="line-height: 30px; height: 30px; color: var(--color)"
  912. >
  913. {{ data.pen.icon }}
  914. </i>
  915. <a class="ml-12 mt-4" @click="iconsDrawer.show = true">
  916. 选择
  917. </a>
  918. <t-drawer
  919. v-model:visible="iconsDrawer.show"
  920. header="选择图标"
  921. :footer="null"
  922. >
  923. <Iconfonts :urls="data.iconUrls" @change="onChangeIcon" />
  924. </t-drawer>
  925. </div>
  926. </t-space>
  927. </t-collapse-panel>
  928. <t-collapse-panel
  929. v-if="data.pen.props.custom"
  930. value="5"
  931. header="属性"
  932. >
  933. <t-space direction="vertical" size="small" class="w-full">
  934. <div v-for="item in data.pen.props.custom" class="form-item">
  935. <label :title="item.label">{{ item.label }}</label>
  936. <t-checkbox
  937. class="ml-8"
  938. v-if="item.type === 'bool'"
  939. v-model="data.pen[item.key]"
  940. @change="changeValue(item.key)"
  941. />
  942. <t-input-number
  943. class="w-full"
  944. v-else-if="item.type === 'number'"
  945. v-model.number="data.pen[item.key]"
  946. theme="column"
  947. :max="item.max"
  948. :min="item.min"
  949. @change="changeValue(item.key)"
  950. :placeholder="item.placeholder"
  951. />
  952. <t-color-picker
  953. class="w-full"
  954. v-else-if="item.type === 'color'"
  955. :enable-alpha="true"
  956. :recent-colors="null"
  957. format="CSS"
  958. :swatch-colors="defaultPureColor"
  959. :color-modes="['monochrome']"
  960. :show-primary-color-preview="false"
  961. v-model="data.pen[item.key]"
  962. @change="changeValue(item.key)"
  963. :placeholder="item.placeholder"
  964. />
  965. <t-select
  966. class="w-full"
  967. v-else-if="item.type === 'select'"
  968. size="small"
  969. :options="item.options"
  970. v-model="data.pen[item.key]"
  971. @change="changeValue(item.key)"
  972. :placeholder="item.placeholder"
  973. />
  974. <t-button
  975. v-else-if="item.type === 'code'"
  976. shape="square"
  977. variant="outline"
  978. style="width: 24px"
  979. @click="showPropsEdit(item)"
  980. >
  981. <t-icon name="ellipsis" slot="icon"
  982. /></t-button>
  983. <t-slider
  984. v-else-if="item.type === 'slider'"
  985. v-model="data.pen[item.key]"
  986. :min="0"
  987. :max="1"
  988. :step="0.01"
  989. @change="changeValue(item.key)"
  990. />
  991. <t-switch
  992. v-else-if="item.type === 'switch'"
  993. v-model="data.pen[item.key]"
  994. @change="changeValue(item.key)"
  995. />
  996. <t-input
  997. class="w-full"
  998. v-else
  999. v-model="data.pen[item.key]"
  1000. @change="changeValue(item.key)"
  1001. :placeholder="item.placeholder"
  1002. />
  1003. </div>
  1004. </t-space>
  1005. </t-collapse-panel>
  1006. </t-collapse>
  1007. <t-divider style="margin: -8px 0" />
  1008. <div class="form-item px-16" style="margin-top: -12px">
  1009. <t-checkbox
  1010. v-model="data.pen.flipX"
  1011. @change="changeValue('flipX')"
  1012. style="width: 90px"
  1013. >
  1014. 水平翻转
  1015. </t-checkbox>
  1016. <t-checkbox
  1017. v-model="data.pen.flipY"
  1018. @change="changeValue('flipY')"
  1019. style="width: 90px"
  1020. >
  1021. 垂直翻转
  1022. </t-checkbox>
  1023. <label style="width: 50px">锚点半径</label>
  1024. <input
  1025. class="ml-4"
  1026. v-model.number="data.pen.anchorRadius"
  1027. style="width: 20px"
  1028. @change="changeValue('anchorRadius')"
  1029. placeholder="4"
  1030. />
  1031. </div>
  1032. <t-divider style="margin: -8px 0" />
  1033. <div class="form-item px-16" style="margin-top: -12px">
  1034. <t-checkbox
  1035. v-model="data.pen.disableRotate"
  1036. @change="changeValue('disableRotate')"
  1037. style="width: 90px"
  1038. >
  1039. 禁止旋转
  1040. </t-checkbox>
  1041. <t-checkbox
  1042. v-model="data.pen.disableSize"
  1043. @change="changeValue('disableSize')"
  1044. style="width: 90px"
  1045. >
  1046. 禁止缩放
  1047. </t-checkbox>
  1048. <t-checkbox
  1049. v-model="data.pen.disableAnchor"
  1050. @change="changeValue('disableAnchor')"
  1051. style="width: 90px"
  1052. >
  1053. 禁用锚点
  1054. </t-checkbox>
  1055. </div>
  1056. <t-divider style="margin: -8px 0" />
  1057. <div class="form-item px-16" style="margin-top: -12px">
  1058. <label style="width: 60px">鼠标提示</label>
  1059. <t-button
  1060. shape="square"
  1061. variant="outline"
  1062. style="width: 24px"
  1063. @click="showTooltip"
  1064. >
  1065. <t-icon name="ellipsis" slot="icon"
  1066. /></t-button>
  1067. </div>
  1068. <t-dialog
  1069. v-if="tooltipDialog.show"
  1070. :visible="true"
  1071. header="鼠标提示"
  1072. @confirm="onOkTooltip"
  1073. @close="tooltipDialog.show = false"
  1074. :width="700"
  1075. >
  1076. <t-radio-group v-model="tooltipDialog.type">
  1077. <t-radio value="1">文字</t-radio>
  1078. <t-radio value="2">函数</t-radio>
  1079. </t-radio-group>
  1080. <div class="py-8">
  1081. <CodeEditor
  1082. v-show="tooltipDialog.type == 1"
  1083. v-model="tooltipDialog.title"
  1084. style="height: 300px"
  1085. />
  1086. <div v-show="tooltipDialog.type == 2">
  1087. <div>function tooltip(pen) {</div>
  1088. <CodeEditor
  1089. v-model="tooltipDialog.titleFnJs"
  1090. class="mt-4"
  1091. style="height: 248px"
  1092. />
  1093. <div class="mt-4">}</div>
  1094. </div>
  1095. </div>
  1096. <div class="gray" style="font-size: 12px">支持Markdown格式</div>
  1097. </t-dialog>
  1098. <t-dialog
  1099. v-if="propsDialog.show"
  1100. :visible="true"
  1101. :header="propsDialog.header"
  1102. @confirm="onOkPropsEdit"
  1103. @close="propsDialog.show = false"
  1104. :width="700"
  1105. >
  1106. <div class="py-8">
  1107. <CodeEditor
  1108. :json="true"
  1109. :language="'json'"
  1110. v-model="propsDialog.value"
  1111. style="height: 300px"
  1112. />
  1113. </div>
  1114. <div class="gray" style="font-size: 12px">
  1115. {{ propsDialog.placeholder }}
  1116. </div>
  1117. </t-dialog>
  1118. <t-space />
  1119. </t-space>
  1120. </t-tab-panel>
  1121. <t-tab-panel :value="2" label="动画">
  1122. <PenAnimates :pen="data.pen" />
  1123. </t-tab-panel>
  1124. <t-tab-panel :value="3" label="数据">
  1125. <PenDatas :pen="data.pen" />
  1126. </t-tab-panel>
  1127. <t-tab-panel :value="4" label="交互">
  1128. <PenEvents :key="data.key" :pen="data.pen" />
  1129. </t-tab-panel>
  1130. <t-tab-panel :value="5" label="结构">
  1131. <ElementTree />
  1132. </t-tab-panel>
  1133. </t-tabs>
  1134. </div>
  1135. </template>
  1136. <script lang="ts" setup>
  1137. import { onBeforeMount, onUnmounted, reactive, ref, watch } from 'vue';
  1138. import CodeEditor from './common/CodeEditor.vue';
  1139. import Iconfonts from './common/Iconfonts.vue';
  1140. import PenAnimates from './PenAnimates.vue';
  1141. import PenDatas from './PenDatas.vue';
  1142. import PenEvents from './PenEvents.vue';
  1143. import ElementTree from './ElementTree.vue';
  1144. import { getCookie } from '@/services/cookie';
  1145. import { useSelection } from '@/services/selections';
  1146. import { autoSave, fonts, inTreePanel } from '@/services/common';
  1147. import { updatePen } from './pen';
  1148. import { MessagePlugin } from 'tdesign-vue-next';
  1149. import { useUser } from '@/services/user';
  1150. import { getter, queryURLParams } from '@meta2d/core';
  1151. import { defaultGradientColor, defaultPureColor } from '@/services/defaults';
  1152. import { getLe5le3d, getLe5leV, getLe5le2d } from '@/services/api';
  1153. import { s8 } from '@/services/random';
  1154. const { user } = useUser();
  1155. const headers = {
  1156. Authorization: 'Bearer ' + (localStorage.token || getCookie('token') || ''),
  1157. };
  1158. const updataData = { directory: '/大屏/图片/默认' };
  1159. const uploadRef = ref();
  1160. const data = reactive<any>({
  1161. tab: 1,
  1162. pen: {},
  1163. rect: {},
  1164. key: s8(),
  1165. });
  1166. const { selections } = useSelection();
  1167. const tooltipDialog = reactive<any>({
  1168. show: false,
  1169. });
  1170. const propsDialog = reactive<any>({
  1171. show: false,
  1172. });
  1173. const iconsDrawer = reactive<any>({
  1174. show: false,
  1175. });
  1176. const aligns = [
  1177. {
  1178. value: 'left',
  1179. label: '左对齐',
  1180. icon: '#l-align-left',
  1181. },
  1182. {
  1183. value: 'center',
  1184. label: '垂直居中对齐',
  1185. icon: '#l-align-center',
  1186. },
  1187. {
  1188. value: 'right',
  1189. label: '右对齐',
  1190. icon: '#l-align-right',
  1191. },
  1192. {
  1193. value: 'top',
  1194. label: '顶部对齐',
  1195. icon: '#l-align-top',
  1196. },
  1197. {
  1198. value: 'middle',
  1199. label: '水平居中对齐',
  1200. icon: '#l-align-middle',
  1201. },
  1202. {
  1203. value: 'bottom',
  1204. label: '底部对齐',
  1205. icon: '#l-align-bottom',
  1206. },
  1207. ];
  1208. const align = (align: string) => {
  1209. meta2d.alignNodesV(align, meta2d.store.active);
  1210. getRect();
  1211. meta2d.render();
  1212. };
  1213. onBeforeMount(() => {
  1214. if (inTreePanel.value) {
  1215. data.tab = 5;
  1216. }
  1217. const d = meta2d.store.data as any;
  1218. if (!d.groups) {
  1219. d.groups = [];
  1220. }
  1221. if (!d.iconUrls) {
  1222. d.iconUrls = [];
  1223. }
  1224. data.iconUrls = d.iconUrls;
  1225. data.groups = d.groups;
  1226. initPenData();
  1227. meta2d.on('translatePens', getRect);
  1228. meta2d.on('resizePens', getRect);
  1229. meta2d.on('rotatePens', getRect);
  1230. });
  1231. function initPenData() {
  1232. data.key = s8(); //触发更新
  1233. data.pen = selections.pen;
  1234. if (!data.pen.props) {
  1235. data.pen.props = {};
  1236. }
  1237. if (!data.pen.globalAlpha && data.pen.globalAlpha !== 0) {
  1238. data.pen.globalAlpha = 1;
  1239. }
  1240. if (!data.pen.dash) {
  1241. data.pen.dash = 0;
  1242. }
  1243. if (!data.pen.props.text) {
  1244. if (data.pen.text || data.pen.name === 'text') {
  1245. data.pen.props.text = true;
  1246. }
  1247. }
  1248. if (!data.pen.props.image) {
  1249. if (data.pen.image) {
  1250. data.pen.props.image = true;
  1251. }
  1252. }
  1253. if (!data.pen.props.icon) {
  1254. if (data.pen.icon) {
  1255. data.pen.props.icon = true;
  1256. }
  1257. }
  1258. if (data.pen.image) {
  1259. data.images = [
  1260. {
  1261. url: data.pen.image,
  1262. },
  1263. ];
  1264. }
  1265. if (!data.pen.tags) {
  1266. data.pen.tags = [];
  1267. }
  1268. if (data.pen.bkType == undefined) {
  1269. data.pen.bkType = 0;
  1270. }
  1271. if (!data.pen.animations) {
  1272. data.pen.animations = [];
  1273. }
  1274. data.pen.shadow = !!data.pen.shadowColor;
  1275. getRect();
  1276. }
  1277. const watcher = watch(() => selections.pen.id, initPenData);
  1278. const getRect = () => {
  1279. data.rect = meta2d.getPenRect(data.pen);
  1280. };
  1281. const decimalPlaces = (val: number) => {
  1282. if (!val) {
  1283. return 0;
  1284. }
  1285. return Math.round(+val * 100) / 100;
  1286. };
  1287. const decimalRound = (val: number) => {
  1288. return Math.round(+val || 0);
  1289. };
  1290. const changeValue = (prop: string) => {
  1291. updatePen(data.pen, prop);
  1292. selections.pen[prop] = getter(data.pen, prop);
  1293. if (prop === 'iframe') {
  1294. getThumbImg();
  1295. }
  1296. };
  1297. const getThumbImg = async () => {
  1298. //改iframe地址后
  1299. let arr = data.pen.iframe.split('?');
  1300. let id = queryURLParams(arr[1]).id;
  1301. if (!id) {
  1302. return;
  1303. }
  1304. let projection = {
  1305. image: 1,
  1306. _id: 1,
  1307. name: 1,
  1308. };
  1309. let res: any;
  1310. if (arr[0].indexOf('2d.le5le') !== -1) {
  1311. res = await getLe5le2d(id, projection);
  1312. } else if (arr[0].indexOf('v.le5le') !== -1) {
  1313. res = await getLe5leV(id, projection);
  1314. } else if (arr[0].indexOf('3d.le5le') !== -1) {
  1315. res = await getLe5le3d(id, projection);
  1316. }
  1317. if (res) {
  1318. data.pen.thumbImg = res.image;
  1319. }
  1320. };
  1321. const changeID = (value: any) => {
  1322. if (!value) {
  1323. initPenData();
  1324. MessagePlugin.error('id 不能为空');
  1325. return;
  1326. }
  1327. const oldID: string = data.pen.id;
  1328. try {
  1329. meta2d.changePenId(oldID, value);
  1330. initPenData();
  1331. } catch (error) {
  1332. console.warn(error.message);
  1333. MessagePlugin.error('id 修改失败,请检查 id 是否重复');
  1334. return;
  1335. }
  1336. };
  1337. const changeRectValue = (prop: string) => {
  1338. data.rect.id = data.pen.id;
  1339. data.rect.ratio = data.pen.ratio;
  1340. updatePen(data.rect, prop);
  1341. };
  1342. const onFontPopupVisible = (val: boolean) => {
  1343. data.fontFamilyPopupVisible = val;
  1344. };
  1345. const onFontFamily = (fontFamily: string) => {
  1346. data.pen.fontFamily = fontFamily;
  1347. data.fontFamilyPopupVisible = false;
  1348. changeValue('fontFamily');
  1349. };
  1350. const beforeUpload = (file: any) => {
  1351. // if (file.size > 5 * 1024 * 1024) {
  1352. // MessagePlugin.warning('上传的图片不能大于5M');
  1353. // return false;
  1354. // }
  1355. if (!(user && user.id)) {
  1356. MessagePlugin.warning('请先登录!');
  1357. return false;
  1358. }
  1359. return true;
  1360. };
  1361. const fileSuccessed = async (content: any) => {
  1362. // meta2d.store.patchFlagsBackground = true;
  1363. // meta2d.setBackgroundImage(content.response.url);
  1364. // meta2d.store.patchFlagsBackground = true;
  1365. data.pen.image = content.response.url || `/file${content.response.filename}`;
  1366. updatePen(data.pen, 'image');
  1367. meta2d.render();
  1368. };
  1369. const fileRemoved = () => {
  1370. // meta2d.setBackgroundImage('');
  1371. // meta2d.store.patchFlagsBackground = true;
  1372. data.pen.image = '';
  1373. updatePen(data.pen, 'image');
  1374. meta2d.render();
  1375. // data.background = [];
  1376. };
  1377. const upload = () => {
  1378. uploadRef.value.triggerUpload();
  1379. };
  1380. const onSelectTag = (tag: string) => {
  1381. data.tagPopupVisible = false;
  1382. if (data.pen.tags.includes(tag)) {
  1383. return;
  1384. }
  1385. data.pen.tags.push(tag);
  1386. changeValue('tags');
  1387. };
  1388. const onChangeInputTag = (currentTags: any, context: any) => {
  1389. const { trigger, index, item } = context;
  1390. if (['tag-remove', 'backspace'].includes(trigger)) {
  1391. data.pen.tags.splice(index, 1);
  1392. }
  1393. if (trigger === 'enter') {
  1394. onSelectTag(item);
  1395. const d = meta2d.store.data as any;
  1396. if (!d.groups.includes(item)) {
  1397. d.groups.push(item);
  1398. data.groups = d.groups;
  1399. }
  1400. data.inputTag = '';
  1401. }
  1402. data.tagPopupVisible = false;
  1403. };
  1404. const showTooltip = () => {
  1405. tooltipDialog.title = data.pen.title || '';
  1406. tooltipDialog.titleFnJs =
  1407. data.pen.titleFnJs || '// 例如:return `${pen.name}<br/>${pen.text}`;';
  1408. tooltipDialog.type = data.pen.titleFnJs ? '2' : '1';
  1409. tooltipDialog.show = true;
  1410. };
  1411. const onOkTooltip = () => {
  1412. if (tooltipDialog.type === '1') {
  1413. data.pen.title = tooltipDialog.title;
  1414. data.pen.titleFnJs = '';
  1415. data.pen.titleFn = null;
  1416. } else {
  1417. data.pen.title = '';
  1418. data.pen.titleFnJs = tooltipDialog.titleFnJs;
  1419. }
  1420. tooltipDialog.show = false;
  1421. };
  1422. const showPropsEdit = (item: any) => {
  1423. propsDialog.key = item.key;
  1424. propsDialog.header = `${item.label}(${item.key})`;
  1425. propsDialog.value = data.pen[item.key];
  1426. propsDialog.placeholder = item.placeholder;
  1427. propsDialog.show = true;
  1428. };
  1429. const onOkPropsEdit = () => {
  1430. if (!propsDialog.value) {
  1431. MessagePlugin.error('数据不满足json格式');
  1432. return;
  1433. }
  1434. data.pen[propsDialog.key] = propsDialog.value;
  1435. updatePen(data.pen, propsDialog.key);
  1436. propsDialog.show = false;
  1437. };
  1438. const onChangeIcon = (params: any) => {
  1439. Object.assign(data.pen, params);
  1440. meta2d.setValue({
  1441. id: data.pen.id,
  1442. icon: params.icon,
  1443. iconFamily: params.iconFamily,
  1444. });
  1445. autoSave(true);
  1446. };
  1447. onUnmounted(() => {
  1448. watcher();
  1449. meta2d.off('translatePens', getRect);
  1450. meta2d.off('resizePens', getRect);
  1451. meta2d.off('rotatePens', getRect);
  1452. });
  1453. </script>
  1454. <style lang="postcss" scoped>
  1455. .props {
  1456. .icons {
  1457. display: flex;
  1458. svg:hover {
  1459. cursor: pointer;
  1460. color: var(--color-primary);
  1461. }
  1462. .btn {
  1463. font-size: 16px;
  1464. margin-right: 16px;
  1465. color: var(--color);
  1466. }
  1467. }
  1468. }
  1469. </style>