PenProps.vue 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604
  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="top">
  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: 64px">背景</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: 64px">悬停</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: 64px">选中</label>
  723. </div>
  724. <div class="form-item">
  725. <label style="width: 32px">前景</label>
  726. <div class="ml-8">
  727. <t-radio-group
  728. size="small"
  729. v-model="data.pen.textType"
  730. :default-value="0"
  731. @change="changeValue('textType')"
  732. >
  733. <t-radio-button :value="0"> 纯色 </t-radio-button>
  734. <t-radio-button :value="1"> 线性渐变 </t-radio-button>
  735. <t-radio-button :value="2"> 径向渐变 </t-radio-button>
  736. </t-radio-group>
  737. <div v-if="data.pen.textType === 0" class="mt-8 -ml-8">
  738. <t-color-picker
  739. class="w-full"
  740. format="CSS"
  741. :swatch-colors="defaultPureColor"
  742. :color-modes="['monochrome']"
  743. :recent-colors="null"
  744. :enable-alpha="true"
  745. :show-primary-color-preview="false"
  746. v-model="data.pen.textColor"
  747. @change="changeValue('textColor')"
  748. />
  749. </div>
  750. <div
  751. v-else-if="data.pen.textType === 1"
  752. class="mt-8 -ml-8"
  753. style="width: 200px"
  754. >
  755. <t-color-picker
  756. class="w-full"
  757. format="CSS"
  758. :enable-alpha="true"
  759. :recent-colors="null"
  760. :swatch-colors="defaultGradientColor"
  761. :color-modes="['linear-gradient']"
  762. :show-primary-color-preview="false"
  763. v-model="data.pen.textGradientColors"
  764. @change="changeValue('textGradientColors')"
  765. />
  766. </div>
  767. <div
  768. v-else-if="data.pen.textType === 2"
  769. class="mt-8 -ml-8"
  770. style="width: 200px"
  771. >
  772. <t-color-picker
  773. class="w-full"
  774. format="CSS"
  775. :enable-alpha="true"
  776. :recent-colors="null"
  777. :swatch-colors="defaultGradientColor"
  778. :color-modes="['linear-gradient']"
  779. :show-primary-color-preview="false"
  780. v-model="data.pen.textGradientColors"
  781. @change="changeValue('textGradientColors')"
  782. />
  783. </div>
  784. </div>
  785. </div>
  786. <div class="form-item">
  787. <t-checkbox
  788. :checked="data.pen.whiteSpace != 'nowrap' ? true : false"
  789. @change="changeValue('whiteSpace')"
  790. style="width: 64px"
  791. >
  792. 换行
  793. </t-checkbox>
  794. <t-checkbox
  795. v-model="data.pen.ellipsis"
  796. @change="changeValue('ellipsis')"
  797. style="width: 68px"
  798. >
  799. 省略号
  800. </t-checkbox>
  801. <t-tooltip content="行高">
  802. <t-input
  803. placeholder="行高"
  804. v-model.number="data.pen.lineHeight"
  805. style="width: 40px"
  806. @change="changeValue('lineHeight')"
  807. />
  808. </t-tooltip>
  809. <t-tooltip content="显示时保留小数位数">
  810. <t-input
  811. class="ml-4"
  812. placeholder="小数"
  813. v-model.number="data.pen.keepDecimal"
  814. style="width: 60px"
  815. @change="changeValue('keepDecimal')"
  816. />
  817. </t-tooltip>
  818. </div>
  819. <div class="form-item" style="margin-top: -4px">
  820. <t-tooltip content="水平偏移">
  821. <t-input
  822. placeholder="X"
  823. v-model.number="data.pen.textLeft"
  824. style="width: 60px; margin-left: -8px"
  825. @change="changeValue('textLeft')"
  826. />
  827. </t-tooltip>
  828. <t-tooltip content="垂直偏移">
  829. <t-input
  830. class="ml-4"
  831. placeholder="Y"
  832. v-model.number="data.pen.textTop"
  833. style="width: 60px"
  834. @change="changeValue('textTop')"
  835. />
  836. </t-tooltip>
  837. <t-tooltip content="宽">
  838. <t-input
  839. class="ml-4"
  840. placeholder="宽"
  841. v-model.number="data.pen.textWidth"
  842. style="width: 60px"
  843. @change="changeValue('textWidth')"
  844. />
  845. </t-tooltip>
  846. <t-tooltip content="高">
  847. <t-input
  848. class="ml-4"
  849. placeholder="高"
  850. v-model.number="data.pen.textHeight"
  851. style="width: 60px"
  852. @change="changeValue('textHeight')"
  853. />
  854. </t-tooltip>
  855. </div>
  856. <div class="flex middle">
  857. <t-checkbox
  858. v-model="data.pen.disableInput"
  859. @change="changeValue('disableInput')"
  860. style="width: 64px"
  861. >
  862. 只读
  863. </t-checkbox>
  864. <t-checkbox
  865. v-model="data.pen.hiddenText"
  866. @change="changeValue('hiddenText')"
  867. style="width: 90px"
  868. >
  869. 隐藏文字
  870. </t-checkbox>
  871. <t-checkbox
  872. v-model="data.pen.textAutoAdjust"
  873. @change="changeValue('textAutoAdjust')"
  874. style="width: 90px"
  875. >
  876. 自动调整
  877. </t-checkbox>
  878. </div>
  879. </t-space>
  880. </t-collapse-panel>
  881. <t-collapse-panel
  882. v-if="data.pen.props.image"
  883. value="3"
  884. header="图片"
  885. >
  886. <t-space direction="vertical" size="small" class="w-full">
  887. <div>
  888. <t-upload
  889. ref="uploadRef"
  890. v-model="data.images"
  891. action="/api/image/upload"
  892. theme="image"
  893. accept="image/*"
  894. :headers="headers"
  895. :data="updataData"
  896. :before-upload="beforeUpload"
  897. draggable
  898. @success="fileSuccessed"
  899. @remove="fileRemoved"
  900. >
  901. <template #fileListDisplay>
  902. <div style="z-index: 20">
  903. <a class="mr-4" @click="upload"> 点击上传 </a>
  904. / 拖拽图片到此区域
  905. </div>
  906. </template>
  907. </t-upload>
  908. </div>
  909. <div class="form-item hover-icons" style="margin-left: -12px">
  910. <t-input
  911. class="ml-4"
  912. label="W"
  913. v-model.number="data.pen.iconWidth"
  914. placeholder="自适应"
  915. min="1"
  916. style="width: 80px"
  917. :format="decimalPlaces"
  918. @change="changeValue('iconWidth')"
  919. />
  920. <t-tooltip
  921. v-if="data.pen.imageRatio"
  922. content="固定比例"
  923. placement="top"
  924. >
  925. <t-icon
  926. name="link"
  927. class="ml-4 hover"
  928. @click="data.pen.imageRatio = !data.pen.imageRatio"
  929. />
  930. </t-tooltip>
  931. <t-tooltip v-else content="不固定比例" placement="top">
  932. <t-icon
  933. name="link-unlink"
  934. class="ml-4 hover icon"
  935. @click="data.pen.imageRatio = !data.pen.imageRatio"
  936. />
  937. </t-tooltip>
  938. <t-input
  939. class="ml-4"
  940. label="H"
  941. placeholder="自适应"
  942. v-model.number="data.pen.iconHeight"
  943. min="1"
  944. style="width: 80px"
  945. :format="decimalPlaces"
  946. @change="changeValue('iconHeight')"
  947. />
  948. <t-checkbox
  949. class="ml-8"
  950. v-model="data.pen.isBottom"
  951. @change="changeValue('isBottom')"
  952. >
  953. 置底
  954. </t-checkbox>
  955. </div>
  956. <div class="flex">
  957. <label style="width: 30px; color: var(--color)">Url:</label>
  958. {{ data.pen.image }}
  959. </div>
  960. </t-space>
  961. </t-collapse-panel>
  962. <t-collapse-panel
  963. v-if="data.pen.props.icon"
  964. value="4"
  965. header="图标"
  966. >
  967. <t-space direction="vertical" size="small" class="w-full">
  968. <div class="form-item">
  969. <label style="width: 32px">图标 </label>
  970. <i
  971. class="ml-8"
  972. :class="data.pen.iconFamily"
  973. style="line-height: 30px; height: 30px; color: var(--color)"
  974. >
  975. {{ data.pen.icon }}
  976. </i>
  977. <a class="ml-12 mt-4" @click="iconsDrawer.show = true">
  978. 选择
  979. </a>
  980. <t-drawer
  981. v-model:visible="iconsDrawer.show"
  982. header="选择图标"
  983. :footer="null"
  984. >
  985. <Iconfonts :urls="data.iconUrls" @change="onChangeIcon" />
  986. </t-drawer>
  987. </div>
  988. </t-space>
  989. </t-collapse-panel>
  990. <!-- <t-collapse-panel
  991. v-if="data.pen.props.custom"
  992. value="5"
  993. header="属性"
  994. >
  995. <t-space direction="vertical" size="small" class="w-full">
  996. <div v-for="item in data.pen.props.custom" class="form-item">
  997. <label :title="item.label">{{ item.label }}</label>
  998. <t-checkbox
  999. class="ml-8"
  1000. v-if="item.type === 'bool'"
  1001. v-model="data.pen[item.key]"
  1002. @change="changeValue(item.key)"
  1003. />
  1004. <t-input-number
  1005. class="w-full"
  1006. v-else-if="item.type === 'number'"
  1007. v-model.number="data.pen[item.key]"
  1008. theme="column"
  1009. :max="item.max"
  1010. :min="item.min"
  1011. @change="changeValue(item.key)"
  1012. :placeholder="item.placeholder"
  1013. />
  1014. <t-color-picker
  1015. class="w-full"
  1016. v-else-if="item.type === 'color'"
  1017. :enable-alpha="true"
  1018. :recent-colors="null"
  1019. format="CSS"
  1020. :swatch-colors="defaultPureColor"
  1021. :color-modes="['monochrome']"
  1022. :show-primary-color-preview="false"
  1023. v-model="data.pen[item.key]"
  1024. @change="changeValue(item.key)"
  1025. :placeholder="item.placeholder"
  1026. />
  1027. <t-select
  1028. class="w-full"
  1029. v-else-if="item.type === 'select'"
  1030. size="small"
  1031. :options="item.options"
  1032. v-model="data.pen[item.key]"
  1033. @change="changeValue(item.key)"
  1034. :placeholder="item.placeholder"
  1035. />
  1036. <t-button
  1037. v-else-if="item.type === 'code'"
  1038. shape="square"
  1039. variant="outline"
  1040. style="width: 24px"
  1041. @click="showPropsEdit(item)"
  1042. >
  1043. <t-icon name="ellipsis" slot="icon"
  1044. /></t-button>
  1045. <t-slider
  1046. v-else-if="item.type === 'slider'"
  1047. v-model="data.pen[item.key]"
  1048. :min="0"
  1049. :max="1"
  1050. :step="0.01"
  1051. @change="changeValue(item.key)"
  1052. />
  1053. <t-switch
  1054. v-else-if="item.type === 'switch'"
  1055. v-model="data.pen[item.key]"
  1056. @change="changeValue(item.key)"
  1057. />
  1058. <t-input
  1059. class="w-full"
  1060. v-else
  1061. v-model="data.pen[item.key]"
  1062. @change="changeValue(item.key)"
  1063. :placeholder="item.placeholder"
  1064. />
  1065. </div>
  1066. </t-space>
  1067. </t-collapse-panel> -->
  1068. </t-collapse>
  1069. <t-divider style="margin: -8px 0" />
  1070. <div class="form-item px-16" style="margin-top: -12px">
  1071. <t-checkbox
  1072. v-model="data.pen.flipX"
  1073. @change="changeValue('flipX')"
  1074. style="width: 90px"
  1075. >
  1076. 水平翻转
  1077. </t-checkbox>
  1078. <t-checkbox
  1079. v-model="data.pen.flipY"
  1080. @change="changeValue('flipY')"
  1081. style="width: 90px"
  1082. >
  1083. 垂直翻转
  1084. </t-checkbox>
  1085. <label style="width: 50px">锚点半径</label>
  1086. <input
  1087. class="ml-4"
  1088. v-model.number="data.pen.anchorRadius"
  1089. style="width: 20px"
  1090. @change="changeValue('anchorRadius')"
  1091. placeholder="4"
  1092. />
  1093. </div>
  1094. <t-divider style="margin: -8px 0" />
  1095. <div class="form-item px-16" style="margin-top: -12px">
  1096. <t-checkbox
  1097. v-model="data.pen.disableRotate"
  1098. @change="changeValue('disableRotate')"
  1099. style="width: 90px"
  1100. >
  1101. 禁止旋转
  1102. </t-checkbox>
  1103. <t-checkbox
  1104. v-model="data.pen.disableSize"
  1105. @change="changeValue('disableSize')"
  1106. style="width: 90px"
  1107. >
  1108. 禁止缩放
  1109. </t-checkbox>
  1110. <t-checkbox
  1111. v-model="data.pen.disableAnchor"
  1112. @change="changeValue('disableAnchor')"
  1113. style="width: 90px"
  1114. >
  1115. 禁用锚点
  1116. </t-checkbox>
  1117. </div>
  1118. <t-divider style="margin: -8px 0" />
  1119. <div class="form-item px-16" style="margin-top: -12px">
  1120. <label style="width: 60px">鼠标提示</label>
  1121. <t-button
  1122. shape="square"
  1123. variant="outline"
  1124. style="width: 24px"
  1125. @click="showTooltip"
  1126. >
  1127. <t-icon name="ellipsis" slot="icon"
  1128. /></t-button>
  1129. </div>
  1130. <t-dialog
  1131. v-if="tooltipDialog.show"
  1132. :visible="true"
  1133. header="鼠标提示"
  1134. @confirm="onOkTooltip"
  1135. @close="tooltipDialog.show = false"
  1136. :width="700"
  1137. >
  1138. <t-radio-group v-model="tooltipDialog.type">
  1139. <t-radio value="1">文字</t-radio>
  1140. <t-radio value="2">函数</t-radio>
  1141. </t-radio-group>
  1142. <div class="py-8">
  1143. <CodeEditor
  1144. v-show="tooltipDialog.type == 1"
  1145. v-model="tooltipDialog.title"
  1146. style="height: 300px"
  1147. />
  1148. <div v-show="tooltipDialog.type == 2">
  1149. <div>function tooltip(pen) {</div>
  1150. <CodeEditor
  1151. v-model="tooltipDialog.titleFnJs"
  1152. class="mt-4"
  1153. style="height: 248px"
  1154. />
  1155. <div class="mt-4">}</div>
  1156. </div>
  1157. </div>
  1158. <div class="gray" style="font-size: 12px">支持Markdown格式</div>
  1159. </t-dialog>
  1160. <t-dialog
  1161. v-if="propsDialog.show"
  1162. :visible="true"
  1163. :header="propsDialog.header"
  1164. @confirm="onOkPropsEdit"
  1165. @close="propsDialog.show = false"
  1166. :width="700"
  1167. >
  1168. <div class="py-8">
  1169. <CodeEditor
  1170. :json="true"
  1171. :language="'json'"
  1172. v-model="propsDialog.value"
  1173. style="height: 300px"
  1174. />
  1175. </div>
  1176. <div class="gray" style="font-size: 12px">
  1177. {{ propsDialog.placeholder }}
  1178. </div>
  1179. </t-dialog>
  1180. <t-space />
  1181. </t-space>
  1182. </t-tab-panel>
  1183. <t-tab-panel :value="2" label="动画">
  1184. <PenAnimates :pen="data.pen" />
  1185. </t-tab-panel>
  1186. <t-tab-panel :value="3" label="数据">
  1187. <PenDatas :pen="data.pen" />
  1188. </t-tab-panel>
  1189. <t-tab-panel :value="4" label="交互">
  1190. <PenEvents :key="data.key" :pen="data.pen" />
  1191. </t-tab-panel>
  1192. <t-tab-panel :value="5" label="结构">
  1193. <ElementTree />
  1194. </t-tab-panel>
  1195. </t-tabs>
  1196. </div>
  1197. </template>
  1198. <script lang="ts" setup>
  1199. import { onBeforeMount, onUnmounted, reactive, ref, watch } from 'vue';
  1200. import CodeEditor from './common/CodeEditor.vue';
  1201. import Iconfonts from './common/Iconfonts.vue';
  1202. import PenAnimates from './PenAnimates.vue';
  1203. import PenDatas from './PenDatas.vue';
  1204. import PenEvents from './PenEvents.vue';
  1205. import ElementTree from './ElementTree.vue';
  1206. import { getCookie } from '@/services/cookie';
  1207. import { useSelection } from '@/services/selections';
  1208. import { autoSave, fonts, inTreePanel } from '@/services/common';
  1209. import { updatePen } from './pen';
  1210. import { MessagePlugin } from 'tdesign-vue-next';
  1211. import { useUser } from '@/services/user';
  1212. import { getter, queryURLParams } from '@meta2d/core';
  1213. import { defaultGradientColor, defaultPureColor } from '@/services/defaults';
  1214. import { getLe5le3d, getLe5leV, getLe5le2d } from '@/services/api';
  1215. import { s8 } from '@/services/random';
  1216. const { user } = useUser();
  1217. const headers = {
  1218. Authorization: 'Bearer ' + (localStorage.token || getCookie('token') || ''),
  1219. };
  1220. const updataData = { directory: '/大屏/图片/默认' };
  1221. const uploadRef = ref();
  1222. const data = reactive<any>({
  1223. tab: 1,
  1224. pen: {},
  1225. rect: {},
  1226. key: s8(),
  1227. });
  1228. const { selections } = useSelection();
  1229. const tooltipDialog = reactive<any>({
  1230. show: false,
  1231. });
  1232. const propsDialog = reactive<any>({
  1233. show: false,
  1234. });
  1235. const iconsDrawer = reactive<any>({
  1236. show: false,
  1237. });
  1238. const aligns = [
  1239. {
  1240. value: 'left',
  1241. label: '左对齐',
  1242. icon: '#l-align-left',
  1243. },
  1244. {
  1245. value: 'center',
  1246. label: '垂直居中对齐',
  1247. icon: '#l-align-center',
  1248. },
  1249. {
  1250. value: 'right',
  1251. label: '右对齐',
  1252. icon: '#l-align-right',
  1253. },
  1254. {
  1255. value: 'top',
  1256. label: '顶部对齐',
  1257. icon: '#l-align-top',
  1258. },
  1259. {
  1260. value: 'middle',
  1261. label: '水平居中对齐',
  1262. icon: '#l-align-middle',
  1263. },
  1264. {
  1265. value: 'bottom',
  1266. label: '底部对齐',
  1267. icon: '#l-align-bottom',
  1268. },
  1269. ];
  1270. const align = (align: string) => {
  1271. meta2d.alignNodesV(align, meta2d.store.active);
  1272. getRect();
  1273. meta2d.render();
  1274. };
  1275. onBeforeMount(() => {
  1276. if (inTreePanel.value) {
  1277. data.tab = 5;
  1278. }
  1279. const d = meta2d.store.data as any;
  1280. if (!d.groups) {
  1281. d.groups = [];
  1282. }
  1283. if (!d.iconUrls) {
  1284. d.iconUrls = [];
  1285. }
  1286. data.iconUrls = d.iconUrls;
  1287. data.groups = d.groups;
  1288. initPenData();
  1289. meta2d.on('translatePens', getRect);
  1290. meta2d.on('resizePens', getRect);
  1291. meta2d.on('rotatePens', getRect);
  1292. });
  1293. function initPenData() {
  1294. data.key = s8(); //触发更新
  1295. data.pen = selections.pen;
  1296. if (!data.pen.props) {
  1297. data.pen.props = {};
  1298. }
  1299. if (!data.pen.globalAlpha && data.pen.globalAlpha !== 0) {
  1300. data.pen.globalAlpha = 1;
  1301. }
  1302. if (!data.pen.dash) {
  1303. data.pen.dash = 0;
  1304. }
  1305. if (!data.pen.props.text) {
  1306. if (data.pen.text || data.pen.name === 'text') {
  1307. data.pen.props.text = true;
  1308. }
  1309. }
  1310. if (!data.pen.props.image) {
  1311. if (data.pen.image) {
  1312. data.pen.props.image = true;
  1313. }
  1314. }
  1315. if (!data.pen.props.icon) {
  1316. if (data.pen.icon) {
  1317. data.pen.props.icon = true;
  1318. }
  1319. }
  1320. if (data.pen.image) {
  1321. data.images = [
  1322. {
  1323. url: data.pen.image,
  1324. },
  1325. ];
  1326. }
  1327. if (!data.pen.tags) {
  1328. data.pen.tags = [];
  1329. }
  1330. if (data.pen.bkType == undefined) {
  1331. data.pen.bkType = 0;
  1332. }
  1333. if (data.pen.textType == undefined) {
  1334. data.pen.textType = 0;
  1335. }
  1336. if (!data.pen.animations) {
  1337. data.pen.animations = [];
  1338. }
  1339. if (!data.pen.whiteSpace) {
  1340. data.pen.whiteSpace = 'nowrap';
  1341. }
  1342. if (data.pen.ellipsis == undefined) {
  1343. data.pen.ellipsis = false;
  1344. }
  1345. data.pen.shadow = !!data.pen.shadowColor;
  1346. getRect();
  1347. }
  1348. const watcher = watch(() => selections.pen.id, initPenData);
  1349. const getRect = () => {
  1350. data.rect = meta2d.getPenRect(data.pen);
  1351. };
  1352. const decimalPlaces = (val: number) => {
  1353. if (!val) {
  1354. return 0;
  1355. }
  1356. return Math.round(+val * 100) / 100;
  1357. };
  1358. const decimalRound = (val: number) => {
  1359. return Math.round(+val || 0);
  1360. };
  1361. const changeValue = (prop: string) => {
  1362. updatePen(data.pen, prop);
  1363. selections.pen[prop] = getter(data.pen, prop);
  1364. if (prop === 'iframe') {
  1365. getThumbImg();
  1366. }
  1367. };
  1368. const getThumbImg = async () => {
  1369. //改iframe地址后
  1370. let arr = data.pen.iframe.split('?');
  1371. let id = queryURLParams(arr[1]).id;
  1372. if (!id) {
  1373. return;
  1374. }
  1375. let projection = {
  1376. image: 1,
  1377. _id: 1,
  1378. name: 1,
  1379. };
  1380. let res: any;
  1381. if (arr[0].indexOf('2d.le5le') !== -1) {
  1382. res = await getLe5le2d(id, projection);
  1383. } else if (arr[0].indexOf('v.le5le') !== -1) {
  1384. res = await getLe5leV(id, projection);
  1385. } else if (arr[0].indexOf('3d.le5le') !== -1) {
  1386. res = await getLe5le3d(id, projection);
  1387. }
  1388. if (res) {
  1389. data.pen.thumbImg = res.image;
  1390. }
  1391. data.pen.onRenderPenRaw?.(data.pen);
  1392. };
  1393. const changeID = (value: any) => {
  1394. if (!value) {
  1395. initPenData();
  1396. MessagePlugin.error('id 不能为空');
  1397. return;
  1398. }
  1399. const oldID: string = data.pen.id;
  1400. try {
  1401. meta2d.changePenId(oldID, value);
  1402. initPenData();
  1403. } catch (error) {
  1404. console.warn(error.message);
  1405. MessagePlugin.error('id 修改失败,请检查 id 是否重复');
  1406. return;
  1407. }
  1408. };
  1409. const changeRectValue = (prop: string) => {
  1410. data.rect.id = data.pen.id;
  1411. data.rect.ratio = data.pen.ratio;
  1412. updatePen(data.rect, prop);
  1413. };
  1414. const onFontPopupVisible = (val: boolean) => {
  1415. data.fontFamilyPopupVisible = val;
  1416. };
  1417. const onFontFamily = (fontFamily: string) => {
  1418. data.pen.fontFamily = fontFamily;
  1419. data.fontFamilyPopupVisible = false;
  1420. changeValue('fontFamily');
  1421. };
  1422. const beforeUpload = (file: any) => {
  1423. // if (file.size > 5 * 1024 * 1024) {
  1424. // MessagePlugin.warning('上传的图片不能大于5M');
  1425. // return false;
  1426. // }
  1427. if (!(user && user.id)) {
  1428. MessagePlugin.warning('请先登录!');
  1429. return false;
  1430. }
  1431. return true;
  1432. };
  1433. const fileSuccessed = async (content: any) => {
  1434. // meta2d.store.patchFlagsBackground = true;
  1435. // meta2d.setBackgroundImage(content.response.url);
  1436. // meta2d.store.patchFlagsBackground = true;
  1437. data.pen.image = content.response.url || `/file${content.response.filename}`;
  1438. updatePen(data.pen, 'image');
  1439. meta2d.render();
  1440. };
  1441. const fileRemoved = () => {
  1442. // meta2d.setBackgroundImage('');
  1443. // meta2d.store.patchFlagsBackground = true;
  1444. data.pen.image = '';
  1445. updatePen(data.pen, 'image');
  1446. meta2d.render();
  1447. // data.background = [];
  1448. };
  1449. const upload = () => {
  1450. uploadRef.value.triggerUpload();
  1451. };
  1452. const onSelectTag = (tag: string) => {
  1453. data.tagPopupVisible = false;
  1454. if (data.pen.tags.includes(tag)) {
  1455. return;
  1456. }
  1457. data.pen.tags.push(tag);
  1458. changeValue('tags');
  1459. };
  1460. const onChangeInputTag = (currentTags: any, context: any) => {
  1461. const { trigger, index, item } = context;
  1462. if (['tag-remove', 'backspace'].includes(trigger)) {
  1463. data.pen.tags.splice(index, 1);
  1464. }
  1465. if (trigger === 'enter') {
  1466. onSelectTag(item);
  1467. const d = meta2d.store.data as any;
  1468. if (!d.groups.includes(item)) {
  1469. d.groups.push(item);
  1470. data.groups = d.groups;
  1471. }
  1472. data.inputTag = '';
  1473. }
  1474. data.tagPopupVisible = false;
  1475. };
  1476. const showTooltip = () => {
  1477. tooltipDialog.title = data.pen.title || '';
  1478. tooltipDialog.titleFnJs =
  1479. data.pen.titleFnJs || '// 例如:return `${pen.name}<br/>${pen.text}`;';
  1480. tooltipDialog.type = data.pen.titleFnJs ? '2' : '1';
  1481. tooltipDialog.show = true;
  1482. };
  1483. const onOkTooltip = () => {
  1484. if (tooltipDialog.type === '1') {
  1485. data.pen.title = tooltipDialog.title;
  1486. data.pen.titleFnJs = '';
  1487. data.pen.titleFn = null;
  1488. } else {
  1489. data.pen.title = '';
  1490. data.pen.titleFnJs = tooltipDialog.titleFnJs;
  1491. }
  1492. tooltipDialog.show = false;
  1493. };
  1494. const showPropsEdit = (item: any) => {
  1495. propsDialog.key = item.key;
  1496. propsDialog.header = `${item.label}(${item.key})`;
  1497. propsDialog.value = data.pen[item.key];
  1498. propsDialog.placeholder = item.placeholder;
  1499. propsDialog.show = true;
  1500. };
  1501. const onOkPropsEdit = () => {
  1502. if (!propsDialog.value) {
  1503. MessagePlugin.error('数据不满足json格式');
  1504. return;
  1505. }
  1506. data.pen[propsDialog.key] = propsDialog.value;
  1507. updatePen(data.pen, propsDialog.key);
  1508. propsDialog.show = false;
  1509. };
  1510. const onChangeIcon = (params: any) => {
  1511. Object.assign(data.pen, params);
  1512. meta2d.setValue({
  1513. id: data.pen.id,
  1514. icon: params.icon,
  1515. iconFamily: params.iconFamily,
  1516. });
  1517. autoSave(true);
  1518. };
  1519. onUnmounted(() => {
  1520. watcher();
  1521. meta2d.off('translatePens', getRect);
  1522. meta2d.off('resizePens', getRect);
  1523. meta2d.off('rotatePens', getRect);
  1524. });
  1525. </script>
  1526. <style lang="postcss" scoped>
  1527. .props {
  1528. .icons {
  1529. display: flex;
  1530. svg:hover {
  1531. cursor: pointer;
  1532. color: var(--color-primary);
  1533. }
  1534. .btn {
  1535. font-size: 16px;
  1536. margin-right: 16px;
  1537. color: var(--color);
  1538. }
  1539. }
  1540. }
  1541. </style>