cread.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116
  1. <template>
  2. <div class="CalligraphyMaster-cread">
  3. <Header />
  4. <div class="bg_main">
  5. <div class="main">
  6. <div class="main-top">
  7. <div class="left">
  8. <span>画布设置:</span>
  9. <div>
  10. <span>长度</span>
  11. <el-input
  12. :readonly="true"
  13. v-model="form.heightText"
  14. style="width: 60px"
  15. ></el-input>
  16. <div class="add_remove">
  17. <img
  18. @click="addCanvasWH('H')"
  19. src="../../assets/teacherdev/sfds-canvas-add.png"
  20. alt=""
  21. />
  22. <img
  23. @click="removeCanvasWH('H')"
  24. src="../../assets/teacherdev/sfds-canvas-remove.png"
  25. alt=""
  26. />
  27. </div>
  28. </div>
  29. <div>
  30. <img src="../../assets/teacherdev/sfds-canvas-line.png" alt="" />
  31. <span>宽度</span>
  32. <el-input
  33. :readonly="true"
  34. v-model="form.widthText"
  35. style="width: 60px"
  36. ></el-input>
  37. <div class="add_remove">
  38. <img
  39. @click="addCanvasWH('W')"
  40. src="../../assets/teacherdev/sfds-canvas-add.png"
  41. alt=""
  42. />
  43. <img
  44. @click="removeCanvasWH('W')"
  45. src="../../assets/teacherdev/sfds-canvas-remove.png"
  46. alt=""
  47. />
  48. </div>
  49. </div>
  50. <div>
  51. <span>背景颜色</span>
  52. <el-color-picker v-model="form.bg_color"></el-color-picker>
  53. </div>
  54. </div>
  55. <div class="right">
  56. <div>
  57. <img src="../../assets/teacherdev/word-save.png" alt="" />
  58. 保存
  59. </div>
  60. <div>
  61. <img src="../../assets/teacherdev/sfds-fb.png" alt="" />
  62. 发布
  63. </div>
  64. <div>
  65. <img src="../../assets/teacherdev/word-download.png" alt="" />
  66. 下载
  67. </div>
  68. </div>
  69. </div>
  70. <div
  71. class="operation"
  72. v-if="changeType == 'text' || changeType == 'luminance'"
  73. >
  74. <template v-if="changeType == 'text'">
  75. <div class="text-operation">
  76. <div class="font_sele">
  77. <div
  78. class="font_sele_input"
  79. @click="FontFamilySele = !FontFamilySele"
  80. >
  81. <span>{{ fontForm.fontFamily }}</span>
  82. <img
  83. src="../../assets/teacherdev/font-sele-down.png"
  84. alt=""
  85. />
  86. </div>
  87. <div v-show="FontFamilySele" class="fontFamily_list">
  88. <div class="Boutque_font">
  89. <span class="one">精品字体</span>
  90. <span
  91. v-for="(item, index) in BoutiqueFontList"
  92. :key="index + 'BoutiqueFon'"
  93. >{{ item }}</span
  94. >
  95. <span class="more">更多...</span>
  96. </div>
  97. <div
  98. class="fontFamily_one"
  99. v-for="(item, index) in fontList"
  100. :key="index + 'font'"
  101. :value="item.fontFamily"
  102. >
  103. <div class="use" v-if="item.RecentUse">
  104. <span>最近使用</span>
  105. </div>
  106. <div class="fontFamily">{{ item.fontFamily }}</div>
  107. <div class="content">
  108. <span>{{ item.content }}</span>
  109. <img
  110. v-if="item.collect"
  111. src="../../assets/teacherdev/font-collect-sele.png"
  112. alt=""
  113. />
  114. <img
  115. v-else
  116. src="../../assets/teacherdev/font-collect.png"
  117. alt=""
  118. />
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. <el-select
  124. v-model="fontForm.fontSize"
  125. style="width: 60px; margin-left: 8px"
  126. >
  127. <el-option
  128. v-for="(item, i) in fontSizeList"
  129. :key="i + 'fontsize'"
  130. :value="item.value"
  131. :label="item.name"
  132. >
  133. </el-option>
  134. </el-select>
  135. <el-select
  136. v-model="fontForm.percent"
  137. style="width: 68px; height: 32px; margin-left: 8px"
  138. >
  139. <el-option
  140. v-for="i in 100"
  141. :key="i + 'fontsize'"
  142. :value="i"
  143. :label="i + '%'"
  144. >
  145. </el-option>
  146. </el-select>
  147. <div class="img_dv">
  148. <img src="../../assets/teacherdev/font-add.png" alt="" />
  149. <img src="../../assets/teacherdev/font-remove.png" alt="" />
  150. <img src="../../assets/teacherdev/font-blod.png" alt="" />
  151. <img src="../../assets/teacherdev/font-red.png" alt="" />
  152. </div>
  153. <el-color-picker
  154. v-model="fontForm.fontColor"
  155. style="margin-left: 8px; width: 60px"
  156. ></el-color-picker>
  157. <div class="img_dv" style="margin-left: 8px">
  158. <img src="../../assets/teacherdev/font-left.png" alt="" />
  159. <img src="../../assets/teacherdev/font-center.png" alt="" />
  160. <img src="../../assets/teacherdev/font-right.png" alt="" />
  161. </div>
  162. <div class="img_dv" style="margin-left: 8px">
  163. <img
  164. src="../../assets/teacherdev/font-line-left-right.png"
  165. alt=""
  166. />
  167. <img
  168. src="../../assets/teacherdev/font-line-top-bottom.png"
  169. alt=""
  170. />
  171. </div>
  172. <div class="img_dv" style="margin-left: 8px">
  173. <img src="../../assets/teacherdev/font-italic.png" alt="" />
  174. <img src="../../assets/teacherdev/font-blod2.png" alt="" />
  175. </div>
  176. </div>
  177. </template>
  178. <template v-else-if="changeType == 'luminance'">
  179. <div class="luminance-operation">
  180. <img
  181. :style="{ filter: `brightness(${changeluminanceNumber()})` }"
  182. src="../../assets/teacherdev/sun.png"
  183. alt=""
  184. />
  185. <div class="line-text">
  186. <div class="DragLine">
  187. <DragLine :min="-100" :max="100" v-model="luminanceNumber" />
  188. </div>
  189. <div class="text">
  190. <span>-100</span>
  191. <span>0</span>
  192. <span>+100</span>
  193. </div>
  194. </div>
  195. </div>
  196. </template>
  197. </div>
  198. <div
  199. class="canvas"
  200. :style="{
  201. marginTop:
  202. changeType == 'text' || changeType == 'luminance' ? 0 : '32px',
  203. }"
  204. >
  205. <div
  206. id="imgCanvas"
  207. ref="imgCanvas"
  208. :style="{
  209. width: form.width + 'px',
  210. height: form.height + 'px',
  211. background: form.bg_color,
  212. }"
  213. ></div>
  214. </div>
  215. <div class="bottom">
  216. <div @click="changeSize">
  217. <img src="../../assets/teacherdev/sfds-tailoring.png" alt="" />
  218. </div>
  219. <el-upload
  220. :accept="'.png,.jpg'"
  221. class="upload-demo"
  222. :show-file-list="false"
  223. :action="url"
  224. :on-preview="handlePreview"
  225. :on-remove="handleRemove"
  226. :multiple="true"
  227. :on-exceed="handleExceed"
  228. :on-success="handleSuccess"
  229. :file-list="fileList"
  230. :before-remove="beforeRemove"
  231. :limit="1"
  232. :before-upload="handlebeforeUplaod"
  233. >
  234. <div>
  235. <img src="../../assets/teacherdev/sfds-image.png" alt="" />
  236. </div>
  237. </el-upload>
  238. <div @click="addText">
  239. <img src="../../assets/teacherdev/sfds-text.png" alt="" />
  240. </div>
  241. <div @click="deleteImage">
  242. <img src="../../assets/teacherdev/sfds-delete.png" alt="" />
  243. </div>
  244. <div @click="changeluminance">
  245. <img src="../../assets/teacherdev/sfds-sun.png" alt="" />
  246. </div>
  247. </div>
  248. </div>
  249. </div>
  250. </div>
  251. </template>
  252. <script>
  253. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  254. //例如:import 《组件名称》from ‘《组件路径》';
  255. import Header from "@/components/Header";
  256. import DragLine from "@/components/DragLine";
  257. import { getToken, removeToken } from "@/utils/auth";
  258. import { WebFileDownload } from "@/api/api";
  259. import "tui-image-editor/dist/tui-image-editor.css";
  260. import "tui-color-picker/dist/tui-color-picker.css";
  261. import ImageEditor from "tui-image-editor";
  262. const locale_zh = {
  263. ZoomIn: "放大",
  264. ZoomOut: "缩小",
  265. Hand: "手掌",
  266. History: "历史",
  267. Resize: "调整宽高",
  268. Crop: "裁剪",
  269. DeleteAll: "全部删除",
  270. Delete: "删除",
  271. Undo: "撤销",
  272. Redo: "反撤销",
  273. Reset: "重置",
  274. Flip: "镜像",
  275. Rotate: "旋转",
  276. Draw: "画",
  277. Shape: "形状标注",
  278. Icon: "图标标注",
  279. Text: "文字标注",
  280. Mask: "遮罩",
  281. Filter: "滤镜",
  282. Bold: "加粗",
  283. Italic: "斜体",
  284. Underline: "下划线",
  285. Left: "左对齐",
  286. Center: "居中",
  287. Right: "右对齐",
  288. Color: "颜色",
  289. "Text size": "字体大小",
  290. Custom: "自定义",
  291. Square: "正方形",
  292. Apply: "应用",
  293. Cancel: "取消",
  294. "Flip X": "X 轴",
  295. "Flip Y": "Y 轴",
  296. Range: "区间",
  297. Stroke: "描边",
  298. Fill: "填充",
  299. Circle: "圆",
  300. Triangle: "三角",
  301. Rectangle: "矩形",
  302. Free: "曲线",
  303. Straight: "直线",
  304. Arrow: "箭头",
  305. "Arrow-2": "箭头2",
  306. "Arrow-3": "箭头3",
  307. "Star-1": "星星1",
  308. "Star-2": "星星2",
  309. Polygon: "多边形",
  310. Location: "定位",
  311. Heart: "心形",
  312. Bubble: "气泡",
  313. "Custom icon": "自定义图标",
  314. "Load Mask Image": "加载蒙层图片",
  315. Grayscale: "灰度",
  316. Blur: "模糊",
  317. Sharpen: "锐化",
  318. Emboss: "浮雕",
  319. "Remove White": "除去白色",
  320. Distance: "距离",
  321. Brightness: "亮度",
  322. Noise: "噪音",
  323. "Color Filter": "彩色滤镜",
  324. Sepia: "棕色",
  325. Sepia2: "棕色2",
  326. Invert: "负片",
  327. Pixelate: "像素化",
  328. Threshold: "阈值",
  329. Tint: "色调",
  330. Multiply: "正片叠底",
  331. Blend: "混合色",
  332. Width: "宽度",
  333. Height: "高度",
  334. "Lock Aspect Ratio": "锁定宽高比例",
  335. };
  336. const customTheme = {
  337. "common.bi.image": "", // 左上角logo图片
  338. "common.bisize.width": "0px",
  339. "common.bisize.height": "0px",
  340. "common.backgroundImage": "none",
  341. "common.backgroundColor": "#f3f4f6",
  342. "common.border": "1px solid #333",
  343. // header
  344. "header.backgroundImage": "none",
  345. "header.backgroundColor": "#f3f4f6",
  346. "header.border": "0px",
  347. // load button
  348. "loadButton.backgroundColor": "#fff",
  349. "loadButton.border": "1px solid #ddd",
  350. "loadButton.color": "#222",
  351. "loadButton.fontFamily": "NotoSans, sans-serif",
  352. "loadButton.fontSize": "12px",
  353. "loadButton.display": "none", // 隐藏
  354. // download button
  355. "downloadButton.backgroundColor": "#fdba3b",
  356. "downloadButton.border": "1px solid #fdba3b",
  357. "downloadButton.color": "#fff",
  358. "downloadButton.fontFamily": "NotoSans, sans-serif",
  359. "downloadButton.fontSize": "12px",
  360. "downloadButton.display": "none", // 隐藏
  361. // icons default
  362. "menu.normalIcon.color": "#8a8a8a",
  363. "menu.activeIcon.color": "#555555",
  364. "menu.disabledIcon.color": "#ccc",
  365. "menu.hoverIcon.color": "#e9e9e9",
  366. "submenu.normalIcon.color": "#8a8a8a",
  367. "submenu.activeIcon.color": "#e9e9e9",
  368. "menu.iconSize.width": "24px",
  369. "menu.iconSize.height": "24px",
  370. "submenu.iconSize.width": "32px",
  371. "submenu.iconSize.height": "32px",
  372. // submenu primary color
  373. "submenu.backgroundColor": "#1e1e1e",
  374. "submenu.partition.color": "#858585",
  375. // submenu labels
  376. "submenu.normalLabel.color": "#858585",
  377. "submenu.normalLabel.fontWeight": "lighter",
  378. "submenu.activeLabel.color": "#fff",
  379. "submenu.activeLabel.fontWeight": "lighter",
  380. // checkbox style
  381. "checkbox.border": "1px solid #ccc",
  382. "checkbox.backgroundColor": "#fff",
  383. // rango style
  384. "range.pointer.color": "#fff",
  385. "range.bar.color": "#666",
  386. "range.subbar.color": "#d1d1d1",
  387. "range.disabledPointer.color": "#414141",
  388. "range.disabledBar.color": "#282828",
  389. "range.disabledSubbar.color": "#414141",
  390. "range.value.color": "#fff",
  391. "range.value.fontWeight": "lighter",
  392. "range.value.fontSize": "11px",
  393. "range.value.border": "1px solid #353535",
  394. "range.value.backgroundColor": "#151515",
  395. "range.title.color": "#fff",
  396. "range.title.fontWeight": "lighter",
  397. // colorpicker style
  398. "colorpicker.button.border": "1px solid #1e1e1e",
  399. "colorpicker.title.color": "#fff",
  400. };
  401. export default {
  402. //import引入的组件需要注入到对象中才能使用
  403. components: {
  404. Header,
  405. DragLine,
  406. },
  407. props: {},
  408. data() {
  409. //这里存放数据
  410. return {
  411. form: {
  412. width: 500,
  413. widthText: "500mm",
  414. height: 500,
  415. heightText: "500mm",
  416. bg_color: "#FF3F3F",
  417. },
  418. BoutiqueFontList: [
  419. "水墨字体",
  420. "古风字体",
  421. "中国风字体",
  422. "书协专家字体",
  423. "电影海报字体",
  424. "国潮字体",
  425. ],
  426. fontSizeList: [
  427. {
  428. name: "5号",
  429. value: 5,
  430. },
  431. ],
  432. fontList: [
  433. {
  434. fontFamily: "方正颜真卿楷书",
  435. content: "忽如一夜春风来",
  436. collect: true,
  437. RecentUse: true,
  438. },
  439. {
  440. fontFamily: "方正颜真卿楷书",
  441. content: "忽如一夜春风来",
  442. collect: false,
  443. RecentUse: false,
  444. },
  445. {
  446. fontFamily: "方正颜真卿楷书",
  447. content: "忽如一夜春风来",
  448. collect: true,
  449. RecentUse: true,
  450. },
  451. {
  452. fontFamily: "方正颜真卿楷书",
  453. content: "忽如一夜春风来",
  454. collect: false,
  455. RecentUse: false,
  456. },
  457. {
  458. fontFamily: "方正颜真卿楷书",
  459. content: "忽如一夜春风来",
  460. collect: true,
  461. RecentUse: true,
  462. },
  463. {
  464. fontFamily: "方正颜真卿楷书",
  465. content: "忽如一夜春风来",
  466. collect: false,
  467. RecentUse: false,
  468. },
  469. {
  470. fontFamily: "方正颜真卿楷书",
  471. content: "忽如一夜春风来",
  472. collect: true,
  473. RecentUse: true,
  474. },
  475. {
  476. fontFamily: "方正颜真卿楷书",
  477. content: "忽如一夜春风来",
  478. collect: false,
  479. RecentUse: false,
  480. },
  481. {
  482. fontFamily: "方正颜真卿楷书",
  483. content: "忽如一夜春风来",
  484. collect: true,
  485. RecentUse: true,
  486. },
  487. {
  488. fontFamily: "方正颜真卿楷书",
  489. content: "忽如一夜春风来",
  490. collect: false,
  491. RecentUse: false,
  492. },
  493. ],
  494. luminanceNumber: 0,
  495. changeType: "",
  496. fontForm: {
  497. fontFamily: "方正颜真卿楷书",
  498. fontSize: 5,
  499. percent: 100,
  500. fontColor: "#FFFFFF",
  501. },
  502. FontFamilySele: false,
  503. loading: false,
  504. fileList: [],
  505. imgCtx: null,
  506. TUI_selectedItem: null,
  507. TUI_selectedFont: "",
  508. instance: null,
  509. };
  510. },
  511. //计算属性 类似于data概念
  512. computed: {
  513. url() {
  514. let userInfor = JSON.parse(getToken());
  515. let UserCode = "",
  516. UserType = "",
  517. SessionID = "";
  518. if (userInfor) {
  519. UserCode = userInfor.user_code;
  520. UserType = userInfor.user_type;
  521. SessionID = userInfor.session_id;
  522. }
  523. return (
  524. process.env.VUE_APP_BASE_API +
  525. `/GCLSFileServer/WebFileUpload?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&SecurityLevel=Mid"`
  526. );
  527. },
  528. },
  529. //监控data中数据变化
  530. watch: {},
  531. //方法集合
  532. methods: {
  533. // 增加画布宽或高
  534. addCanvasWH(type) {
  535. if (type == "W") {
  536. if (this.form.width == 500) {
  537. this.$message.warning("已达到上限");
  538. return;
  539. }
  540. this.form.width++;
  541. this.form.widthText = this.form.width + "mm";
  542. } else {
  543. if (this.form.height == 500) {
  544. this.$message.warning("已达到上限");
  545. return;
  546. }
  547. this.form.height++;
  548. this.form.heightText = this.form.height + "mm";
  549. }
  550. },
  551. // 减少画布宽或高
  552. removeCanvasWH(type) {
  553. if (type == "W") {
  554. if (this.form.width == 0) {
  555. return;
  556. }
  557. this.form.width--;
  558. this.form.widthText = this.form.width + "mm";
  559. } else {
  560. if (this.form.height == 0) {
  561. return;
  562. }
  563. this.form.height--;
  564. this.form.heightText = this.form.height + "mm";
  565. }
  566. },
  567. // 添加文字
  568. addText() {
  569. this.changeType = "text";
  570. },
  571. // 修改亮度
  572. changeluminance() {
  573. this.changeType = "luminance";
  574. },
  575. // 计算css所需亮度
  576. changeluminanceNumber() {
  577. if (this.luminanceNumber == 0) {
  578. return 1;
  579. }
  580. if (this.luminanceNumber > 0) {
  581. return 1 + (this.luminanceNumber / 100) * 2;
  582. } else {
  583. return Math.abs(Math.abs(this.luminanceNumber) - 100) / 100;
  584. }
  585. },
  586. // 裁剪
  587. changeSize() {
  588. if (!this.instance) {
  589. this.$message.warning("请先上传图片");
  590. return;
  591. }
  592. this.instance.ui._actions.crop.cancel();
  593. },
  594. initCanvasImage() {
  595. this.loading = this.$loading({
  596. lock: true,
  597. text: "Loading",
  598. spinner: "el-icon-loading",
  599. background: "rgba(0, 0, 0, 0.7)",
  600. });
  601. // 直接使用跨域 请求文件流转url 再使用
  602. WebFileDownload({
  603. FileID: this.fileList[0].file_id,
  604. }).then((res) => {
  605. const objectUrl = window.URL.createObjectURL(res);
  606. this.instance = new ImageEditor(document.querySelector("#imgCanvas"), {
  607. includeUI: {
  608. loadImage: {
  609. path: objectUrl,
  610. name: "image",
  611. },
  612. menu: [
  613. "resize",
  614. "crop",
  615. "rotate",
  616. "draw",
  617. "shape",
  618. "icon",
  619. "text",
  620. "filter",
  621. ], // 底部菜单按钮列表 隐藏镜像flip和遮罩mask
  622. initMenu: "draw", // 默认打开的菜单项
  623. menuBarPosition: "bottom", // 菜单所在的位置
  624. locale: locale_zh, // 本地化语言为中文
  625. theme: customTheme, // 自定义样式
  626. },
  627. cssMaxWidth: this.form.width, // canvas 最大宽度
  628. cssMaxHeight: this.form.heigt, // canvas 最大高度
  629. });
  630. let fontArray = [
  631. "Arial",
  632. "Arial Black",
  633. "Caveat",
  634. "Comic Sans MS",
  635. "Courier New",
  636. "Georgia1",
  637. "Impact",
  638. "Lobster Two",
  639. "Lucida Console",
  640. "Luckiest Guy",
  641. "Open Sans",
  642. "Pacifico",
  643. "Palatino Linotype",
  644. "Press Start 2P",
  645. "Roboto",
  646. "Tahoma",
  647. "Tangerine",
  648. "Times New Roman",
  649. "Tourney",
  650. "Ultra",
  651. "Verdana",
  652. "Symbol",
  653. "Webdings",
  654. "Wingdings",
  655. ];
  656. let fontSelectHTML =
  657. '<select #fontselect class="form-select font-selector">';
  658. for (let i = 0; i < fontArray.length; i++) {
  659. let selected = "";
  660. if (i == 0) {
  661. selected = "selected";
  662. }
  663. fontSelectHTML +=
  664. '<option style="font-family:' +
  665. fontArray[i] +
  666. ' !important;" value="' +
  667. fontArray[i] +
  668. '" ' +
  669. selected +
  670. ">" +
  671. fontArray[i] +
  672. "</option>";
  673. }
  674. fontSelectHTML += "</select>";
  675. let textMenuAlign = document.querySelector(
  676. ".tui-image-editor-menu-text .tie-text-align-button"
  677. );
  678. textMenuAlign.insertAdjacentHTML("afterbegin", fontSelectHTML);
  679. document
  680. .querySelector(".font-selector")
  681. .addEventListener("change", () =>
  682. this.TUI_updateFontOnText($(".font-selector option:selected").val())
  683. );
  684. this.instance.on("objectActivated", (props) => {
  685. this.TUI_selectedItem = props;
  686. this.TUI_updateFontSelected(props);
  687. console.log("TUI_selectedItem", props);
  688. });
  689. this.loading.close();
  690. });
  691. },
  692. TUI_updateFontOnText(font) {
  693. console.log("TUI_updateFontOnText", font, this.TUI_selectedItem.id);
  694. if (font) {
  695. this.TUI_selectedFont = font;
  696. }
  697. if (font && this.TUI_selectedItem) {
  698. this.instance.changeTextStyle(this.TUI_selectedItem.id, {
  699. fontFamily: font,
  700. });
  701. }
  702. },
  703. TUI_updateFontSelected(layer) {
  704. console.log("TUI_updateFontSelected", layer);
  705. if (layer.fontFamily) {
  706. document.querySelector(".font-selector").value = layer.fontFamily;
  707. this.TUI_selectedFont = layer.fontFamily;
  708. }
  709. },
  710. // 删除上传的图片
  711. deleteImage() {
  712. this.fileList = [];
  713. },
  714. handlebeforeUplaod(file) {
  715. if (file.size > 20 * 1024 * 1024) {
  716. this.$message.warning("上传文件大小不能超过20M");
  717. return false; //必须返回false
  718. }
  719. this.loading = this.$loading({
  720. lock: true,
  721. text: "Loading",
  722. spinner: "el-icon-loading",
  723. background: "rgba(0, 0, 0, 0.7)",
  724. });
  725. },
  726. handleSuccess(response, file, fileList) {
  727. if (response.status == 1) {
  728. this.fileList = response.file_info_list;
  729. this.loading.close();
  730. this.initCanvasImage();
  731. } else if (response.status == -1) {
  732. this.loading.close();
  733. removeToken();
  734. this.$message.warning(response.error);
  735. this.$router.push("/login");
  736. } else {
  737. this.loading.close();
  738. }
  739. },
  740. handleRemove(file, fileList) {},
  741. handlePreview(file) {},
  742. handleExceed(files, fileList) {
  743. this.$message.warning(
  744. `当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
  745. files.length + fileList.length
  746. } 个文件`
  747. );
  748. },
  749. beforeRemove(file, filleList) {},
  750. },
  751. //生命周期 - 创建完成(可以访问当前this实例)
  752. created() {},
  753. //生命周期 - 挂载完成(可以访问DOM元素)
  754. mounted() {},
  755. //生命周期-创建之前
  756. beforeCreated() {},
  757. //生命周期-挂载之前
  758. beforeMount() {},
  759. //生命周期-更新之前
  760. beforUpdate() {},
  761. //生命周期-更新之后
  762. updated() {},
  763. //生命周期-销毁之前
  764. beforeDestory() {},
  765. //生命周期-销毁完成
  766. destoryed() {},
  767. //如果页面有keep-alive缓存功能,这个函数会触发
  768. activated() {},
  769. };
  770. </script>
  771. <style lang="scss" scoped>
  772. /* @import url(); 引入css类 */
  773. .CalligraphyMaster-cread {
  774. height: 100%;
  775. position: relative;
  776. .bg_main {
  777. background: #f7f7f7;
  778. min-height: 100%;
  779. padding-top: 24px;
  780. padding-bottom: 70px;
  781. .main {
  782. width: 1168px;
  783. margin: 0 auto;
  784. padding: 16px;
  785. background: #ffffff;
  786. .main-top {
  787. display: flex;
  788. justify-content: space-between;
  789. .left {
  790. display: flex;
  791. align-items: center;
  792. font-weight: 400;
  793. font-size: 14px;
  794. color: #000000;
  795. > div {
  796. display: flex;
  797. align-items: center;
  798. margin-right: 8px;
  799. > img {
  800. width: 16px;
  801. height: 16px;
  802. margin-right: 8px;
  803. }
  804. .add_remove {
  805. display: flex;
  806. flex-wrap: wrap;
  807. align-items: center;
  808. width: 10px;
  809. margin-left: 8px;
  810. img {
  811. width: 10px;
  812. height: 10px;
  813. cursor: pointer;
  814. }
  815. > :nth-child(1) {
  816. margin-bottom: 1px;
  817. }
  818. }
  819. }
  820. span {
  821. margin-right: 8px;
  822. }
  823. }
  824. .right {
  825. display: flex;
  826. div {
  827. margin-left: 16px;
  828. width: 96px;
  829. height: 40px;
  830. background: #ffffff;
  831. border: 1px solid rgba(0, 0, 0, 0.08);
  832. border-radius: 4px;
  833. display: flex;
  834. align-items: center;
  835. justify-content: center;
  836. cursor: pointer;
  837. img {
  838. width: 24px;
  839. height: 24px;
  840. margin-right: 8px;
  841. }
  842. }
  843. }
  844. }
  845. .operation {
  846. margin-top: 33px;
  847. }
  848. .text-operation {
  849. height: 48px;
  850. border: 1px solid rgba(0, 0, 0, 0.08);
  851. border-radius: 8px 8px 0px 0px;
  852. border-bottom: none;
  853. display: flex;
  854. align-items: center;
  855. padding: 0 16px;
  856. .font_sele {
  857. position: relative;
  858. .font_sele_input {
  859. width: 193px;
  860. height: 32px;
  861. padding: 0 6px;
  862. background: #ffffff;
  863. border: 1px solid rgba(0, 0, 0, 0.08);
  864. border-radius: 4px;
  865. display: flex;
  866. align-items: center;
  867. justify-content: space-between;
  868. cursor: pointer;
  869. > span {
  870. font-weight: 400;
  871. font-size: 14px;
  872. line-height: 20px;
  873. color: #000000;
  874. }
  875. > img {
  876. width: 16px;
  877. height: 16px;
  878. }
  879. }
  880. .fontFamily_list {
  881. position: absolute;
  882. top: 39px;
  883. left: 0;
  884. width: 468px;
  885. background: #ffffff;
  886. border-width: 0px 1px 1px 1px;
  887. border-style: solid;
  888. border-color: #dbdbdb;
  889. height: 520px;
  890. overflow: auto;
  891. .fontFamily_one {
  892. padding: 12px 24px 16px 32px;
  893. border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  894. position: relative;
  895. .use {
  896. width: 80px;
  897. height: 80px;
  898. background: url("../../assets/teacherdev/font-use.png");
  899. background-size: cover;
  900. position: absolute;
  901. left: -20px;
  902. top: -20px;
  903. -webkit-transform: scale(0.5);
  904. span {
  905. color: #ffffff;
  906. font-weight: 400;
  907. font-size: 16px;
  908. position: absolute;
  909. transform: translateX(-3px) translateY(20px) rotate(-45deg);
  910. }
  911. }
  912. .fontFamily {
  913. font-weight: 400;
  914. font-size: 14px;
  915. line-height: 20px;
  916. color: rgba(0, 0, 0, 0.5);
  917. }
  918. .content {
  919. margin-top: 8px;
  920. display: flex;
  921. justify-content: space-between;
  922. span {
  923. font-weight: 400;
  924. font-size: 32px;
  925. line-height: 150%;
  926. color: #000000;
  927. }
  928. img {
  929. width: 24px;
  930. height: 24px;
  931. cursor: pointer;
  932. }
  933. }
  934. }
  935. }
  936. }
  937. .Boutque_font {
  938. padding: 16px 12px 0 12px;
  939. background: #f0f0f0;
  940. font-weight: 400;
  941. font-size: 14px;
  942. line-height: 20px;
  943. color: rgba(0, 0, 0, 0.6);
  944. cursor: default;
  945. span {
  946. display: inline-block;
  947. margin: 0 12px 12px 12px;
  948. }
  949. .one {
  950. color: #000000;
  951. }
  952. .more {
  953. color: rgba(0, 0, 0, 0.35);
  954. cursor: pointer;
  955. }
  956. }
  957. .img_dv {
  958. img {
  959. width: 26px;
  960. height: 26px;
  961. cursor: pointer;
  962. margin-left: 8px;
  963. }
  964. }
  965. }
  966. .luminance-operation {
  967. width: 440px;
  968. margin: 0 auto;
  969. display: flex;
  970. > img {
  971. width: 24px;
  972. height: 24px;
  973. }
  974. .line-text {
  975. margin-left: 17px;
  976. .DragLine {
  977. margin-top: 7px;
  978. }
  979. .text {
  980. margin-top: 8px;
  981. display: flex;
  982. justify-content: space-between;
  983. font-weight: 400;
  984. font-size: 12px;
  985. line-height: 20px;
  986. color: #919c9e;
  987. }
  988. }
  989. }
  990. .canvas {
  991. height: 500px;
  992. border: 1px solid rgba(0, 0, 0, 0.1);
  993. display: flex;
  994. justify-content: center;
  995. align-items: center;
  996. }
  997. .bottom {
  998. margin-top: 40px;
  999. display: flex;
  1000. justify-content: center;
  1001. div {
  1002. width: 48px;
  1003. height: 40px;
  1004. background: #ffffff;
  1005. border: 1px solid rgba(0, 0, 0, 0.08);
  1006. border-radius: 4px;
  1007. display: flex;
  1008. align-items: center;
  1009. justify-content: center;
  1010. cursor: pointer;
  1011. margin: 0 16px;
  1012. img {
  1013. width: 32px;
  1014. height: 32px;
  1015. }
  1016. }
  1017. }
  1018. }
  1019. }
  1020. }
  1021. </style>
  1022. <style lang="scss">
  1023. .CalligraphyMaster-cread {
  1024. .main-top {
  1025. .left {
  1026. .el-input__inner {
  1027. padding: 0 5px;
  1028. }
  1029. .el-color-picker__color {
  1030. border: none;
  1031. }
  1032. .el-icon-close:before {
  1033. content: "";
  1034. }
  1035. .el-icon-arrow-down:before {
  1036. content: "";
  1037. }
  1038. .el-color-picker__color-inner {
  1039. position: absolute;
  1040. left: 3px;
  1041. top: 3px;
  1042. right: 0;
  1043. bottom: 0;
  1044. width: 24px;
  1045. height: 24px;
  1046. }
  1047. }
  1048. }
  1049. .text-operation {
  1050. .el-color-picker__trigger {
  1051. width: 60px;
  1052. height: 32px;
  1053. }
  1054. .el-color-picker__empty,
  1055. .el-color-picker__icon {
  1056. left: 72%;
  1057. }
  1058. .el-color-picker__color {
  1059. width: 28px;
  1060. }
  1061. .el-icon-close:before,
  1062. .el-icon-arrow-down:before {
  1063. color: gray;
  1064. }
  1065. .el-color-picker__color-inner {
  1066. position: absolute;
  1067. left: -1px;
  1068. top: -1px;
  1069. right: 0;
  1070. bottom: 0;
  1071. width: 100%;
  1072. height: 100%;
  1073. border: 1px solid rgba(0, 0, 0, 0.08);
  1074. border-radius: 2px;
  1075. }
  1076. .el-input__inner {
  1077. padding: 0 8px;
  1078. }
  1079. .el-input__inner,
  1080. .el-input__suffix {
  1081. height: 32px;
  1082. }
  1083. .el-input__icon {
  1084. line-height: 32px;
  1085. }
  1086. }
  1087. }
  1088. </style>