cread.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230
  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" v-if="1 == 2">
  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 @click="downLoad">
  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 class="canvas" style="margin-top: 16px">
  199. <div
  200. id="imgCanvas"
  201. ref="imgCanvas"
  202. :style="{
  203. width: form.width + 'px',
  204. height: form.height + 'px',
  205. background: form.bg_color,
  206. }"
  207. ></div>
  208. </div>
  209. <div class="bottom" v-if="1 == 2">
  210. <div @click="changeSize">
  211. <img src="../../assets/teacherdev/sfds-tailoring.png" alt="" />
  212. </div>
  213. <!-- <el-upload
  214. :accept="'.png,.jpg'"
  215. class="upload-demo"
  216. :show-file-list="false"
  217. :action="url"
  218. :on-preview="handlePreview"
  219. :on-remove="handleRemove"
  220. :multiple="true"
  221. :on-exceed="handleExceed"
  222. :on-success="handleSuccess"
  223. :file-list="fileList"
  224. :before-remove="beforeRemove"
  225. :limit="1"
  226. :before-upload="handlebeforeUplaod"
  227. >
  228. <div>
  229. <img src="../../assets/teacherdev/sfds-image.png" alt="" />
  230. </div>
  231. </el-upload> -->
  232. <div @click="addText">
  233. <img src="../../assets/teacherdev/sfds-text.png" alt="" />
  234. </div>
  235. <div @click="deleteImage">
  236. <img src="../../assets/teacherdev/sfds-delete.png" alt="" />
  237. </div>
  238. <div @click="changeluminance">
  239. <img src="../../assets/teacherdev/sfds-sun.png" alt="" />
  240. </div>
  241. </div>
  242. </div>
  243. </div>
  244. </div>
  245. </template>
  246. <script>
  247. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  248. //例如:import 《组件名称》from ‘《组件路径》';
  249. import Header from "@/components/Header";
  250. import DragLine from "@/components/DragLine";
  251. import { getToken, removeToken } from "@/utils/auth";
  252. import { WebFileDownload } from "@/api/api";
  253. import "tui-image-editor/dist/tui-image-editor.css";
  254. import "tui-color-picker/dist/tui-color-picker.css";
  255. import ImageEditor from "tui-image-editor";
  256. const locale_zh = {
  257. ZoomIn: "放大",
  258. ZoomOut: "缩小",
  259. Hand: "手掌",
  260. History: "历史",
  261. Resize: "调整宽高",
  262. Crop: "裁剪",
  263. DeleteAll: "全部删除",
  264. Delete: "删除",
  265. Undo: "撤销",
  266. Redo: "反撤销",
  267. Reset: "重置",
  268. Flip: "镜像",
  269. Rotate: "旋转",
  270. Draw: "画笔",
  271. Shape: "形状标注",
  272. Icon: "图标标注",
  273. Text: "文字标注",
  274. Mask: "上传图片",
  275. Filter: "滤镜",
  276. Bold: "加粗",
  277. Italic: "斜体",
  278. Underline: "下划线",
  279. Left: "左对齐",
  280. Center: "居中",
  281. Right: "右对齐",
  282. Color: "颜色",
  283. "Text size": "字体大小",
  284. Custom: "自定义",
  285. Square: "正方形",
  286. Apply: "应用",
  287. Cancel: "取消",
  288. "Flip X": "X 轴",
  289. "Flip Y": "Y 轴",
  290. Range: "区间",
  291. Stroke: "描边",
  292. Fill: "填充",
  293. Circle: "圆",
  294. Triangle: "三角",
  295. Rectangle: "矩形",
  296. Free: "曲线",
  297. Straight: "直线",
  298. Arrow: "箭头",
  299. "Arrow-2": "箭头2",
  300. "Arrow-3": "箭头3",
  301. "Star-1": "星星1",
  302. "Star-2": "星星2",
  303. Polygon: "多边形",
  304. Location: "定位",
  305. Heart: "心形",
  306. Bubble: "气泡",
  307. "Custom icon": "自定义图标",
  308. "Load Mask Image": "加载蒙层图片",
  309. Grayscale: "灰度",
  310. Blur: "模糊",
  311. Sharpen: "锐化",
  312. Emboss: "浮雕",
  313. "Remove White": "除去白色",
  314. Distance: "距离",
  315. Brightness: "亮度",
  316. Noise: "噪音",
  317. "Color Filter": "彩色滤镜",
  318. Sepia: "棕色",
  319. Sepia2: "棕色2",
  320. Invert: "负片",
  321. Pixelate: "像素化",
  322. Threshold: "阈值",
  323. Tint: "色调",
  324. Multiply: "正片叠底",
  325. Blend: "混合色",
  326. Width: "宽度",
  327. Height: "高度",
  328. "Lock Aspect Ratio": "锁定宽高比例",
  329. };
  330. const customTheme = {
  331. "common.bi.image": "", // 左上角logo图片
  332. "common.bisize.width": "0px",
  333. "common.bisize.height": "0px",
  334. "common.backgroundImage": "none",
  335. "common.backgroundColor": "#f3f4f6",
  336. "common.border": "1px solid #333",
  337. // header
  338. "header.backgroundImage": "none",
  339. "header.backgroundColor": "#f3f4f6",
  340. "header.border": "0px",
  341. // load button
  342. "loadButton.backgroundColor": "#fff",
  343. "loadButton.border": "1px solid #ddd",
  344. "loadButton.color": "#222",
  345. "loadButton.fontFamily": "NotoSans, sans-serif",
  346. "loadButton.fontSize": "12px",
  347. "loadButton.display": "none", // 隐藏
  348. // download button
  349. "downloadButton.backgroundColor": "#fdba3b",
  350. "downloadButton.border": "1px solid #fdba3b",
  351. "downloadButton.color": "#fff",
  352. "downloadButton.fontFamily": "NotoSans, sans-serif",
  353. "downloadButton.fontSize": "12px",
  354. "downloadButton.display": "none", // 隐藏
  355. // icons default
  356. "menu.normalIcon.color": "#8a8a8a",
  357. "menu.activeIcon.color": "#555555",
  358. "menu.disabledIcon.color": "#ccc",
  359. "menu.hoverIcon.color": "#e9e9e9",
  360. "submenu.normalIcon.color": "#8a8a8a",
  361. "submenu.activeIcon.color": "#e9e9e9",
  362. "menu.iconSize.width": "24px",
  363. "menu.iconSize.height": "24px",
  364. "submenu.iconSize.width": "32px",
  365. "submenu.iconSize.height": "32px",
  366. // submenu primary color
  367. "submenu.backgroundColor": "#1e1e1e",
  368. "submenu.partition.color": "#858585",
  369. // submenu labels
  370. "submenu.normalLabel.color": "#858585",
  371. "submenu.normalLabel.fontWeight": "lighter",
  372. "submenu.activeLabel.color": "#fff",
  373. "submenu.activeLabel.fontWeight": "lighter",
  374. // checkbox style
  375. "checkbox.border": "1px solid #ccc",
  376. "checkbox.backgroundColor": "#fff",
  377. // rango style
  378. "range.pointer.color": "#fff",
  379. "range.bar.color": "#666",
  380. "range.subbar.color": "#d1d1d1",
  381. "range.disabledPointer.color": "#414141",
  382. "range.disabledBar.color": "#282828",
  383. "range.disabledSubbar.color": "#414141",
  384. "range.value.color": "#fff",
  385. "range.value.fontWeight": "lighter",
  386. "range.value.fontSize": "11px",
  387. "range.value.border": "1px solid #353535",
  388. "range.value.backgroundColor": "#151515",
  389. "range.title.color": "#fff",
  390. "range.title.fontWeight": "lighter",
  391. // colorpicker style
  392. "colorpicker.button.border": "1px solid #1e1e1e",
  393. "colorpicker.title.color": "#fff",
  394. };
  395. export default {
  396. //import引入的组件需要注入到对象中才能使用
  397. components: {
  398. Header,
  399. DragLine,
  400. },
  401. props: {},
  402. data() {
  403. //这里存放数据
  404. return {
  405. form: {
  406. width: 500,
  407. widthText: "500mm",
  408. height: 500,
  409. heightText: "500mm",
  410. bg_color: "#FF3F3F",
  411. },
  412. BoutiqueFontList: [
  413. "水墨字体",
  414. "古风字体",
  415. "中国风字体",
  416. "书协专家字体",
  417. "电影海报字体",
  418. "国潮字体",
  419. ],
  420. fontSizeList: [
  421. {
  422. name: "5号",
  423. value: 5,
  424. },
  425. ],
  426. fontList: [
  427. {
  428. fontFamily: "方正颜真卿楷书",
  429. content: "忽如一夜春风来",
  430. collect: true,
  431. RecentUse: true,
  432. },
  433. {
  434. fontFamily: "方正颜真卿楷书",
  435. content: "忽如一夜春风来",
  436. collect: false,
  437. RecentUse: false,
  438. },
  439. {
  440. fontFamily: "方正颜真卿楷书",
  441. content: "忽如一夜春风来",
  442. collect: true,
  443. RecentUse: true,
  444. },
  445. {
  446. fontFamily: "方正颜真卿楷书",
  447. content: "忽如一夜春风来",
  448. collect: false,
  449. RecentUse: false,
  450. },
  451. {
  452. fontFamily: "方正颜真卿楷书",
  453. content: "忽如一夜春风来",
  454. collect: true,
  455. RecentUse: true,
  456. },
  457. {
  458. fontFamily: "方正颜真卿楷书",
  459. content: "忽如一夜春风来",
  460. collect: false,
  461. RecentUse: false,
  462. },
  463. {
  464. fontFamily: "方正颜真卿楷书",
  465. content: "忽如一夜春风来",
  466. collect: true,
  467. RecentUse: true,
  468. },
  469. {
  470. fontFamily: "方正颜真卿楷书",
  471. content: "忽如一夜春风来",
  472. collect: false,
  473. RecentUse: false,
  474. },
  475. {
  476. fontFamily: "方正颜真卿楷书",
  477. content: "忽如一夜春风来",
  478. collect: true,
  479. RecentUse: true,
  480. },
  481. {
  482. fontFamily: "方正颜真卿楷书",
  483. content: "忽如一夜春风来",
  484. collect: false,
  485. RecentUse: false,
  486. },
  487. ],
  488. luminanceNumber: 0,
  489. changeType: "",
  490. fontForm: {
  491. fontFamily: "方正颜真卿楷书",
  492. fontSize: 5,
  493. percent: 100,
  494. fontColor: "#FFFFFF",
  495. },
  496. FontFamilySele: false,
  497. loading: false,
  498. fileList: [],
  499. imgCtx: null,
  500. TUI_selectedItem: null,
  501. TUI_selectedFont: "",
  502. instance: null,
  503. imgUrl: "../../assets/login/bg-login.png",
  504. };
  505. },
  506. //计算属性 类似于data概念
  507. computed: {
  508. url() {
  509. let userInfor = JSON.parse(getToken());
  510. let UserCode = "",
  511. UserType = "",
  512. SessionID = "";
  513. if (userInfor) {
  514. UserCode = userInfor.user_code;
  515. UserType = userInfor.user_type;
  516. SessionID = userInfor.session_id;
  517. }
  518. return (
  519. process.env.VUE_APP_BASE_API +
  520. `/GCLSFileServer/WebFileUpload?UserCode=${UserCode}&UserType=${UserType}&SessionID=${SessionID}&SecurityLevel=Mid"`
  521. );
  522. },
  523. },
  524. //监控data中数据变化
  525. watch: {},
  526. //方法集合
  527. methods: {
  528. // 增加画布宽或高
  529. addCanvasWH(type) {
  530. if (type == "W") {
  531. if (this.form.width == 500) {
  532. this.$message.warning("已达到上限");
  533. return;
  534. }
  535. this.form.width++;
  536. this.form.widthText = this.form.width + "mm";
  537. } else {
  538. if (this.form.height == 500) {
  539. this.$message.warning("已达到上限");
  540. return;
  541. }
  542. this.form.height++;
  543. this.form.heightText = this.form.height + "mm";
  544. }
  545. },
  546. // 减少画布宽或高
  547. removeCanvasWH(type) {
  548. if (type == "W") {
  549. if (this.form.width == 0) {
  550. return;
  551. }
  552. this.form.width--;
  553. this.form.widthText = this.form.width + "mm";
  554. } else {
  555. if (this.form.height == 0) {
  556. return;
  557. }
  558. this.form.height--;
  559. this.form.heightText = this.form.height + "mm";
  560. }
  561. },
  562. // 添加文字
  563. addText() {
  564. this.changeType = "text";
  565. },
  566. // 修改亮度
  567. changeluminance() {
  568. this.changeType = "luminance";
  569. },
  570. // 计算css所需亮度
  571. changeluminanceNumber() {
  572. if (this.luminanceNumber == 0) {
  573. return 1;
  574. }
  575. if (this.luminanceNumber > 0) {
  576. return 1 + (this.luminanceNumber / 100) * 2;
  577. } else {
  578. return Math.abs(Math.abs(this.luminanceNumber) - 100) / 100;
  579. }
  580. },
  581. // 裁剪
  582. changeSize() {
  583. this.instance.ui._actions.crop.cancel();
  584. },
  585. initCanvasImage() {
  586. this.loading = this.$loading({
  587. lock: true,
  588. text: "Loading",
  589. spinner: "el-icon-loading",
  590. background: "rgba(0, 0, 0, 0.7)",
  591. });
  592. // const objectUrl = window.URL.createObjectURL("");
  593. this.instance = new ImageEditor(document.querySelector("#imgCanvas"), {
  594. includeUI: {
  595. loadImage: {
  596. path: "https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/c1d7a1feb60346449c1a64893888989a~tplv-k3u1fbpfcp-watermark.image", //"https://img2.baidu.com/it/u=1395980100,2999837177&fm=253&fmt=auto&app=120&f=JPEG?w=1200&h=675",
  597. name: "image",
  598. },
  599. menu: [
  600. "mask",
  601. "resize",
  602. "crop",
  603. "rotate",
  604. "draw",
  605. "shape",
  606. "icon",
  607. "text",
  608. // "filter",
  609. ], // 底部菜单按钮列表 隐藏镜像flip和遮罩mask
  610. //initMenu: "none", // 默认打开的菜单项
  611. menuBarPosition: "bottom", // 菜单所在的位置
  612. locale: locale_zh, // 本地化语言为中文
  613. theme: customTheme, // 自定义样式
  614. },
  615. cssMaxWidth: 500, //this.form.width, // canvas 最大宽度
  616. cssMaxHeight: 500, //this.form.height, // canvas 最大高度
  617. usageStatistics: false,
  618. });
  619. $(".tie-mask-apply").css("display", "none");
  620. let fontArray = null;
  621. if (sessionStorage.getItem("fontSelectList")) {
  622. fontArray = JSON.parse(sessionStorage.getItem("fontSelectList"));
  623. } else {
  624. fontArray = [
  625. {
  626. value: "fzbsxjf",
  627. img: require("../../assets/teacherdev/fzbsxjf.png"),
  628. },
  629. {
  630. value: "fzbysk",
  631. img: require("../../assets/teacherdev/fzbysk.png"),
  632. },
  633. {
  634. value: "fzcbzbksjf",
  635. img: require("../../assets/teacherdev/fzcbzbksjf.png"),
  636. },
  637. {
  638. value: "fzfyksjc",
  639. img: require("../../assets/teacherdev/fzfyksjc.png"),
  640. },
  641. {
  642. value: "fzskbxkk",
  643. img: require("../../assets/teacherdev/fzskbxkk.png"),
  644. },
  645. {
  646. value: "fz1",
  647. img: require("../../assets/teacherdev/fzmz.png"),
  648. },
  649. ];
  650. }
  651. // let fontArray = [
  652. // "FZLTH",
  653. // "Arial",
  654. // "Arial Black",
  655. // "Caveat",
  656. // "Comic Sans MS",
  657. // "Courier New",
  658. // "Georgia1",
  659. // "Impact",
  660. // "Lobster Two",
  661. // "Lucida Console",
  662. // "Luckiest Guy",
  663. // "Open Sans",
  664. // "Pacifico",
  665. // "Palatino Linotype",
  666. // "Press Start 2P",
  667. // "Roboto",
  668. // "Tahoma",
  669. // "Tangerine",
  670. // "Times New Roman",
  671. // "Tourney",
  672. // "Ultra",
  673. // "Verdana",
  674. // "Symbol",
  675. // "Webdings",
  676. // "Wingdings",
  677. // ];
  678. let fontSelectHTML =
  679. '<div class="font-select-box tui-image-editor-button"><input class="font-select-value" value="' +
  680. fontArray[0].value +
  681. '" readonly /><label>字体</label><ul #fontselect class="form-select font-selector font-select-list">';
  682. for (let i = 0; i < fontArray.length; i++) {
  683. let classname = i === 0 ? "active" : "";
  684. fontSelectHTML +=
  685. '<li value="' +
  686. fontArray[i].value +
  687. '" class="' +
  688. classname +
  689. '"><img src="' +
  690. fontArray[i].img +
  691. '" /></li>';
  692. }
  693. fontSelectHTML += "</ul></div>";
  694. let textMenuAlign = document.querySelector(
  695. ".tui-image-editor-menu-text .tui-image-editor-submenu-item"
  696. );
  697. textMenuAlign.insertAdjacentHTML("afterbegin", fontSelectHTML);
  698. let _this = this;
  699. $(".font-selector li")
  700. .off("click")
  701. .bind("click", function () {
  702. let value = $(this).attr("value");
  703. _this.TUI_updateFontOnText(value);
  704. $(".font-select-box input").val(value);
  705. $(".font-selector").css("display", "none");
  706. $(this).addClass("active").siblings().removeClass("active");
  707. sessionStorage.setItem("fontSelectFamily", JSON.stringify(value));
  708. let index = $(this).index();
  709. let arr = JSON.parse(JSON.stringify(fontArray[index]));
  710. let fontSelectList = JSON.parse(JSON.stringify(fontArray));
  711. fontSelectList.splice(index, 1);
  712. fontSelectList.unshift(arr);
  713. sessionStorage.setItem(
  714. "fontSelectList",
  715. JSON.stringify(fontSelectList)
  716. );
  717. });
  718. $(".font-select-box input").click(function () {
  719. if ($(".font-selector").css("display") == "flex") {
  720. $(".font-selector").css("display", "none");
  721. } else {
  722. $(".font-selector").css("display", "flex");
  723. }
  724. });
  725. this.instance.on("objectActivated", (props) => {
  726. this.TUI_selectedItem = props;
  727. this.TUI_updateFontSelected(props);
  728. console.log("TUI_selectedItem", props);
  729. });
  730. this.loading.close();
  731. },
  732. TUI_updateFontOnText(font) {
  733. if (font) {
  734. this.TUI_selectedFont = font;
  735. }
  736. if (font && this.TUI_selectedItem) {
  737. this.instance.changeTextStyle(this.TUI_selectedItem.id, {
  738. fontFamily: font,
  739. });
  740. }
  741. },
  742. TUI_updateFontSelected(layer) {
  743. console.log("TUI_updateFontSelected", layer);
  744. if (layer.fontFamily) {
  745. document.querySelector(".font-select-box input").value =
  746. layer.fontFamily;
  747. this.TUI_selectedFont = layer.fontFamily;
  748. }
  749. },
  750. // 删除上传的图片
  751. deleteImage() {
  752. this.fileList = [];
  753. },
  754. handlebeforeUplaod(file) {
  755. if (file.size > 20 * 1024 * 1024) {
  756. this.$message.warning("上传文件大小不能超过20M");
  757. return false; //必须返回false
  758. }
  759. this.loading = this.$loading({
  760. lock: true,
  761. text: "Loading",
  762. spinner: "el-icon-loading",
  763. background: "rgba(0, 0, 0, 0.7)",
  764. });
  765. },
  766. handleSuccess(response, file, fileList) {
  767. if (response.status == 1) {
  768. this.fileList = response.file_info_list;
  769. this.loading.close();
  770. this.initCanvasImage();
  771. } else if (response.status == -1) {
  772. this.loading.close();
  773. removeToken();
  774. this.$message.warning(response.error);
  775. this.$router.push("/login");
  776. } else {
  777. this.loading.close();
  778. }
  779. },
  780. handleRemove(file, fileList) {},
  781. handlePreview(file) {},
  782. handleExceed(files, fileList) {
  783. this.$message.warning(
  784. `当前限制选择 1 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
  785. files.length + fileList.length
  786. } 个文件`
  787. );
  788. },
  789. beforeRemove(file, filleList) {},
  790. downLoad() {
  791. let dataURL = this.instance.toDataURL();
  792. var base64 = dataURL.toString(); // imgSrc 就是base64哈
  793. var byteCharacters = atob(
  794. base64.replace(/^data:image\/(png|jpeg|jpg);base64,/, "")
  795. );
  796. var byteNumbers = new Array(byteCharacters.length);
  797. for (var i = 0; i < byteCharacters.length; i++) {
  798. byteNumbers[i] = byteCharacters.charCodeAt(i);
  799. }
  800. var byteArray = new Uint8Array(byteNumbers);
  801. var blob = new Blob([byteArray], {
  802. type: undefined,
  803. });
  804. var aLink = document.createElement("a");
  805. aLink.download = "书法大师.jpg"; //这里写保存时的图片名称
  806. aLink.href = URL.createObjectURL(blob);
  807. aLink.click();
  808. },
  809. },
  810. //生命周期 - 创建完成(可以访问当前this实例)
  811. created() {},
  812. //生命周期 - 挂载完成(可以访问DOM元素)
  813. mounted() {
  814. this.initCanvasImage();
  815. },
  816. //生命周期-创建之前
  817. beforeCreated() {},
  818. //生命周期-挂载之前
  819. beforeMount() {},
  820. //生命周期-更新之前
  821. beforUpdate() {},
  822. //生命周期-更新之后
  823. updated() {},
  824. //生命周期-销毁之前
  825. beforeDestory() {},
  826. //生命周期-销毁完成
  827. destoryed() {},
  828. //如果页面有keep-alive缓存功能,这个函数会触发
  829. activated() {},
  830. };
  831. </script>
  832. <style lang="scss" scoped>
  833. /* @import url(); 引入css类 */
  834. .CalligraphyMaster-cread {
  835. height: 100%;
  836. position: relative;
  837. .bg_main {
  838. background: #f7f7f7;
  839. min-height: 100%;
  840. padding-top: 24px;
  841. padding-bottom: 70px;
  842. .main {
  843. width: 968px;
  844. margin: 0 auto;
  845. padding: 16px;
  846. background: #ffffff;
  847. .main-top {
  848. display: flex;
  849. justify-content: flex-end;
  850. .left {
  851. display: flex;
  852. align-items: center;
  853. font-weight: 400;
  854. font-size: 14px;
  855. color: #000000;
  856. > div {
  857. display: flex;
  858. align-items: center;
  859. margin-right: 8px;
  860. > img {
  861. width: 16px;
  862. height: 16px;
  863. margin-right: 8px;
  864. }
  865. .add_remove {
  866. display: flex;
  867. flex-wrap: wrap;
  868. align-items: center;
  869. width: 10px;
  870. margin-left: 8px;
  871. img {
  872. width: 10px;
  873. height: 10px;
  874. cursor: pointer;
  875. }
  876. > :nth-child(1) {
  877. margin-bottom: 1px;
  878. }
  879. }
  880. }
  881. span {
  882. margin-right: 8px;
  883. }
  884. }
  885. .right {
  886. display: flex;
  887. div {
  888. margin-left: 16px;
  889. width: 96px;
  890. height: 40px;
  891. background: #ffffff;
  892. border: 1px solid rgba(0, 0, 0, 0.08);
  893. border-radius: 4px;
  894. display: flex;
  895. align-items: center;
  896. justify-content: center;
  897. cursor: pointer;
  898. img {
  899. width: 24px;
  900. height: 24px;
  901. margin-right: 8px;
  902. }
  903. }
  904. }
  905. }
  906. .operation {
  907. margin-top: 33px;
  908. }
  909. .text-operation {
  910. height: 48px;
  911. border: 1px solid rgba(0, 0, 0, 0.08);
  912. border-radius: 8px 8px 0px 0px;
  913. border-bottom: none;
  914. display: flex;
  915. align-items: center;
  916. padding: 0 16px;
  917. .font_sele {
  918. position: relative;
  919. .font_sele_input {
  920. width: 193px;
  921. height: 32px;
  922. padding: 0 6px;
  923. background: #ffffff;
  924. border: 1px solid rgba(0, 0, 0, 0.08);
  925. border-radius: 4px;
  926. display: flex;
  927. align-items: center;
  928. justify-content: space-between;
  929. cursor: pointer;
  930. > span {
  931. font-weight: 400;
  932. font-size: 14px;
  933. line-height: 20px;
  934. color: #000000;
  935. }
  936. > img {
  937. width: 16px;
  938. height: 16px;
  939. }
  940. }
  941. .fontFamily_list {
  942. position: absolute;
  943. top: 39px;
  944. left: 0;
  945. width: 468px;
  946. background: #ffffff;
  947. border-width: 0px 1px 1px 1px;
  948. border-style: solid;
  949. border-color: #dbdbdb;
  950. height: 520px;
  951. overflow: auto;
  952. .fontFamily_one {
  953. padding: 12px 24px 16px 32px;
  954. border-bottom: 1px solid rgba(0, 0, 0, 0.08);
  955. position: relative;
  956. .use {
  957. width: 80px;
  958. height: 80px;
  959. background: url("../../assets/teacherdev/font-use.png");
  960. background-size: cover;
  961. position: absolute;
  962. left: -20px;
  963. top: -20px;
  964. -webkit-transform: scale(0.5);
  965. span {
  966. color: #ffffff;
  967. font-weight: 400;
  968. font-size: 16px;
  969. position: absolute;
  970. transform: translateX(-3px) translateY(20px) rotate(-45deg);
  971. }
  972. }
  973. .fontFamily {
  974. font-weight: 400;
  975. font-size: 14px;
  976. line-height: 20px;
  977. color: rgba(0, 0, 0, 0.5);
  978. }
  979. .content {
  980. margin-top: 8px;
  981. display: flex;
  982. justify-content: space-between;
  983. span {
  984. font-weight: 400;
  985. font-size: 32px;
  986. line-height: 150%;
  987. color: #000000;
  988. }
  989. img {
  990. width: 24px;
  991. height: 24px;
  992. cursor: pointer;
  993. }
  994. }
  995. }
  996. }
  997. }
  998. .Boutque_font {
  999. padding: 16px 12px 0 12px;
  1000. background: #f0f0f0;
  1001. font-weight: 400;
  1002. font-size: 14px;
  1003. line-height: 20px;
  1004. color: rgba(0, 0, 0, 0.6);
  1005. cursor: default;
  1006. span {
  1007. display: inline-block;
  1008. margin: 0 12px 12px 12px;
  1009. }
  1010. .one {
  1011. color: #000000;
  1012. }
  1013. .more {
  1014. color: rgba(0, 0, 0, 0.35);
  1015. cursor: pointer;
  1016. }
  1017. }
  1018. .img_dv {
  1019. img {
  1020. width: 26px;
  1021. height: 26px;
  1022. cursor: pointer;
  1023. margin-left: 8px;
  1024. }
  1025. }
  1026. }
  1027. .luminance-operation {
  1028. width: 440px;
  1029. margin: 0 auto;
  1030. display: flex;
  1031. > img {
  1032. width: 24px;
  1033. height: 24px;
  1034. }
  1035. .line-text {
  1036. margin-left: 17px;
  1037. .DragLine {
  1038. margin-top: 7px;
  1039. }
  1040. .text {
  1041. margin-top: 8px;
  1042. display: flex;
  1043. justify-content: space-between;
  1044. font-weight: 400;
  1045. font-size: 12px;
  1046. line-height: 20px;
  1047. color: #919c9e;
  1048. }
  1049. }
  1050. }
  1051. .canvas {
  1052. height: 600px;
  1053. border: 1px solid rgba(0, 0, 0, 0.1);
  1054. display: flex;
  1055. justify-content: center;
  1056. align-items: center;
  1057. }
  1058. .bottom {
  1059. display: flex;
  1060. justify-content: center;
  1061. div {
  1062. width: 48px;
  1063. height: 40px;
  1064. background: #ffffff;
  1065. border: 1px solid rgba(0, 0, 0, 0.08);
  1066. border-radius: 4px;
  1067. display: flex;
  1068. align-items: center;
  1069. justify-content: center;
  1070. cursor: pointer;
  1071. margin: 0 16px;
  1072. img {
  1073. width: 32px;
  1074. height: 32px;
  1075. }
  1076. }
  1077. }
  1078. }
  1079. }
  1080. }
  1081. </style>
  1082. <style lang="scss">
  1083. .CalligraphyMaster-cread {
  1084. // 图片编辑器操作栏
  1085. //.tui-image-editor-controls {
  1086. // display: none;
  1087. //}
  1088. //.tui-image-editor-container .tui-image-editor-main-container {
  1089. //height: 100%;
  1090. //}
  1091. .main-top {
  1092. .left {
  1093. .el-input__inner {
  1094. padding: 0 5px;
  1095. }
  1096. .el-color-picker__color {
  1097. border: none;
  1098. }
  1099. .el-icon-close:before {
  1100. content: "";
  1101. }
  1102. .el-icon-arrow-down:before {
  1103. content: "";
  1104. }
  1105. .el-color-picker__color-inner {
  1106. position: absolute;
  1107. left: 3px;
  1108. top: 3px;
  1109. right: 0;
  1110. bottom: 0;
  1111. width: 24px;
  1112. height: 24px;
  1113. }
  1114. }
  1115. }
  1116. .text-operation {
  1117. .el-color-picker__trigger {
  1118. width: 60px;
  1119. height: 32px;
  1120. }
  1121. .el-color-picker__empty,
  1122. .el-color-picker__icon {
  1123. left: 72%;
  1124. }
  1125. .el-color-picker__color {
  1126. width: 28px;
  1127. }
  1128. .el-icon-close:before,
  1129. .el-icon-arrow-down:before {
  1130. color: gray;
  1131. }
  1132. .el-color-picker__color-inner {
  1133. position: absolute;
  1134. left: -1px;
  1135. top: -1px;
  1136. right: 0;
  1137. bottom: 0;
  1138. width: 100%;
  1139. height: 100%;
  1140. border: 1px solid rgba(0, 0, 0, 0.08);
  1141. border-radius: 2px;
  1142. }
  1143. .el-input__inner {
  1144. padding: 0 8px;
  1145. }
  1146. .el-input__inner,
  1147. .el-input__suffix {
  1148. height: 32px;
  1149. }
  1150. .el-input__icon {
  1151. line-height: 32px;
  1152. }
  1153. }
  1154. .font-select-box {
  1155. position: relative;
  1156. width: 100px;
  1157. display: inline-block;
  1158. input {
  1159. width: 100%;
  1160. height: 30px;
  1161. border: none;
  1162. outline: none;
  1163. display: block;
  1164. margin-bottom: 5px;
  1165. border-radius: 2px;
  1166. padding: 0 3px;
  1167. }
  1168. }
  1169. .font-select-list {
  1170. display: flex;
  1171. width: 200px;
  1172. flex-flow: wrap;
  1173. position: absolute;
  1174. z-index: 1;
  1175. left: 0;
  1176. top: 30px;
  1177. display: none;
  1178. max-height: 120px;
  1179. overflow: auto;
  1180. li {
  1181. background: #ffffff;
  1182. font-size: 0;
  1183. padding: 0 5px;
  1184. cursor: pointer;
  1185. img {
  1186. width: 100%;
  1187. }
  1188. p {
  1189. color: #0f0f0f;
  1190. font-size: 14px;
  1191. text-align: left;
  1192. line-height: 20px;
  1193. }
  1194. &:hover {
  1195. background: #cfcfcf;
  1196. }
  1197. &.active {
  1198. background: #dbdbdb;
  1199. }
  1200. }
  1201. }
  1202. }
  1203. </style>