PenProps.vue 47 KB

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