FreewriteLettle.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. <!-- -->
  2. <template>
  3. <div class="practice practiceSingleNPC">
  4. <i class="el-icon-close close-icon" @click="changePraShow()"></i>
  5. <div class="right-content">
  6. <SvgIcon icon-class="hanzi-writer-bg" class="character-target-bg" />
  7. <div class="right-strockred">
  8. <template v-if="!hasPlay && data && data.strokes_image_url">
  9. <img class="img" :src="data.strokes_image_url" alt="" />
  10. </template>
  11. <FreeWriteQP
  12. id="esign"
  13. ref="esign"
  14. :bg-color.sync="bgColor"
  15. :height="height"
  16. :is-crop="isCrop"
  17. :line-color="hanzicolor"
  18. :line-width="hanziweight"
  19. :width="width"
  20. class="vueEsign"
  21. />
  22. <a class="clean-btn" @click="resetHuahua">
  23. <SvgIcon icon-class="reset" class="reset-btn" />
  24. </a>
  25. </div>
  26. <ul class="nav-list">
  27. <li :class="currenHzData && currenHzData.history ? '' : 'disabled'" @click="play()">播放</li>
  28. <li @click="handleWriteImg">保存</li>
  29. </ul>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import FreeWriteQP from './FreeWriteQP.vue';
  35. export default {
  36. components: {
  37. FreeWriteQP,
  38. },
  39. props: {
  40. currentTreeID: {
  41. type: String,
  42. default: '',
  43. },
  44. currentHz: {
  45. type: String,
  46. default: '',
  47. },
  48. currenHzData: {
  49. type: Object,
  50. default: () => ({
  51. strokes_image_url: '',
  52. history: [],
  53. }),
  54. },
  55. rowIndex: {
  56. type: Number,
  57. default: 0,
  58. },
  59. colIndex: {
  60. type: Number,
  61. default: 0,
  62. },
  63. },
  64. data() {
  65. return {
  66. width: 256,
  67. height: 256,
  68. bgColor: '',
  69. isCrop: false,
  70. // learn_mode: "",
  71. playStorkes: false,
  72. navIndex: 0,
  73. colorsList: ['#404040', '#f65d4d', '#19b068', '#52a1ea', '#ff8c49'],
  74. weightList: [6, 10],
  75. colorIndex: 0,
  76. penIndex: 0,
  77. hanzicolor: '',
  78. hanziweight: '',
  79. imgOrCans: false,
  80. hasPlay: false,
  81. data: null,
  82. };
  83. },
  84. computed: {},
  85. watch: {},
  86. // 生命周期 - 创建完成(可以访问当前this实例)
  87. created() {
  88. let _this = this;
  89. let color = _this.colorsList[_this.colorIndex];
  90. _this.hanzicolor = color;
  91. _this.hanziweight = 6;
  92. if (_this.currenHzData && _this.currenHzData.strokes_image_url) {
  93. _this.imgOrCans = true;
  94. }
  95. _this.data = JSON.parse(JSON.stringify(_this.currenHzData));
  96. },
  97. // 生命周期 - 挂载完成(可以访问DOM元素)
  98. mounted() {},
  99. beforeCreate() {}, // 生命周期 - 创建之前
  100. beforeMount() {}, // 生命周期 - 挂载之前
  101. beforeUpdate() {}, // 生命周期 - 更新之前
  102. updated() {}, // 生命周期 - 更新之后
  103. beforeDestroy() {}, // 生命周期 - 销毁之前
  104. destroyed() {}, // 生命周期 - 销毁完成
  105. activated() {},
  106. // 方法集合
  107. methods: {
  108. play() {
  109. let _this = this;
  110. if (this.currenHzData && this.currenHzData.history) {
  111. if (this.hasPlay) {
  112. this.$message.warning('请等待播放完成');
  113. return;
  114. }
  115. this.$refs.esign.reset();
  116. this.hasPlay = true;
  117. let c = document.getElementById('esign');
  118. let cxt = document.getElementById('esign').getContext('2d');
  119. cxt.clearRect(0, 0, c.width, c.height);
  120. let history = null;
  121. history = _this.currenHzData.history;
  122. const len = history.length;
  123. let i = 0;
  124. const runner = () => {
  125. i += 1;
  126. if (i < len) {
  127. _this.$refs.esign.draw(null, history[i][0], history[i][1]);
  128. requestAnimationFrame(runner);
  129. } else {
  130. _this.hasPlay = false;
  131. }
  132. };
  133. requestAnimationFrame(runner);
  134. }
  135. },
  136. changeNav(index) {
  137. this.navIndex = index;
  138. },
  139. changeColor(index) {
  140. let _this = this;
  141. _this.colorIndex = index;
  142. let color = _this.colorsList[index];
  143. _this.hanzicolor = color;
  144. },
  145. changeLearnMode(mode) {
  146. this.learn_mode = mode;
  147. },
  148. resetHuahua() {
  149. let _this = this;
  150. if (_this.hasPlay) {
  151. _this.$message.warning('请等待播放完成');
  152. return;
  153. }
  154. _this.imgOrCans = false;
  155. _this.$refs.esign.reset();
  156. if (_this.data) {
  157. _this.data.strokes_image_url = '';
  158. }
  159. _this.$emit('deleteWriteRecord', _this.rowIndex, _this.colIndex, _this.currentHz);
  160. // this.removeImage();
  161. },
  162. removeImage() {
  163. let _this = this;
  164. if (_this.data) {
  165. // let MethodName = 'teaching-practice_manager-DeleteMyHZHandwrittenRecord';
  166. // let data = {
  167. // hz_handwritten_record_id: this.data.hz_handwritten_record_id,
  168. // };
  169. // LearnWebSI(MethodName, data).then((res) => {
  170. _this.$message.success('删除成功');
  171. _this.data = {};
  172. _this.$emit('deleteWriteRecord', _this.rowIndex, _this.colIndex);
  173. // });
  174. }
  175. },
  176. // 不保存到记录列表
  177. handleWriteImg() {
  178. if (this.$refs.esign.history.length === 0) return;
  179. this.$refs.esign.generate().then((res) => {
  180. let Book_img = res.replace('data:image/png;base64,', '');
  181. let write_img = `data:image/png;base64,${Book_img}`;
  182. let answer = {};
  183. answer = {
  184. hz: this.currentHz,
  185. strokes_content: JSON.stringify(this.$refs.esign.history),
  186. strokes_image_url: write_img,
  187. };
  188. this.$emit('changeCurQue', answer, this.colIndex);
  189. let obj = {
  190. history: this.$refs.esign.history,
  191. strokes_image_url: write_img,
  192. };
  193. this.$emit('closeIfFreeShow', obj, this.rowIndex, this.colIndex);
  194. // this.$message.warning("请先书写在保存");
  195. });
  196. },
  197. // 保存到记录列表
  198. handleWriteImg_save() {
  199. this.$refs.esign
  200. .generate()
  201. .then((res) => {
  202. let Book_img = res.replace('data:image/png;base64,', '');
  203. let write_img = `data:image/png;base64,${Book_img}`;
  204. let answer = {};
  205. answer = {
  206. hz: this.currentHz,
  207. strokes_content: JSON.stringify(this.$refs.esign.history),
  208. strokes_image_url: write_img,
  209. };
  210. this.$emit('changeCurQue', answer, this.colIndex);
  211. this.$message.success('保存成功!');
  212. let obj = {
  213. hz_handwritten_record_id: res.hz_handwritten_record_id,
  214. history: this.$refs.esign.history,
  215. strokes_image_url: write_img,
  216. };
  217. this.$emit('closeIfFreeShow', obj, this.rowIndex, this.colIndex);
  218. })
  219. .catch(() => {
  220. this.$message.warning('请先书写在保存');
  221. });
  222. },
  223. changePraShow() {
  224. this.$emit('changePraShow');
  225. },
  226. }, // 如果页面有keep-alive缓存功能,这个函数会触发
  227. };
  228. </script>
  229. <style lang="scss" scoped>
  230. .practice {
  231. position: relative;
  232. width: 320px;
  233. max-height: 400px;
  234. margin: 0 auto;
  235. background: #f3f3f3;
  236. border-radius: 8px;
  237. box-shadow: 0 4px 16px rgba(0, 0, 0, 15%);
  238. .clean-btn {
  239. position: absolute;
  240. right: 8px;
  241. bottom: 8px;
  242. width: 16px;
  243. height: 16px;
  244. margin: 0 4px;
  245. color: $text-color;
  246. cursor: pointer;
  247. &:hover {
  248. color: #000;
  249. }
  250. }
  251. .close-icon {
  252. position: absolute;
  253. top: 0;
  254. right: 8px;
  255. z-index: 2;
  256. width: 32px;
  257. height: 32px;
  258. padding: 8px;
  259. cursor: pointer;
  260. }
  261. .Book_content {
  262. position: relative;
  263. box-sizing: border-box;
  264. display: flex;
  265. align-items: flex-start;
  266. width: 100%;
  267. height: 100%;
  268. }
  269. .left-content {
  270. display: flex;
  271. flex-direction: column;
  272. justify-content: center;
  273. width: 144px;
  274. .left-content-pra {
  275. height: 162px;
  276. }
  277. }
  278. .right-content {
  279. position: relative;
  280. box-sizing: border-box;
  281. display: flex;
  282. flex-direction: column;
  283. align-items: center;
  284. justify-content: flex-start;
  285. width: 288px;
  286. height: 360px;
  287. padding: 30px 16px;
  288. margin: 0 auto;
  289. background: #f3f3f3;
  290. border-radius: 16px;
  291. .nav-list {
  292. display: flex;
  293. align-items: center;
  294. justify-content: space-between;
  295. width: 100%;
  296. height: 34px;
  297. padding: 0;
  298. margin-top: 16px;
  299. list-style: none;
  300. > li {
  301. width: 124px;
  302. height: 34px;
  303. font-size: 14px;
  304. font-style: normal;
  305. font-weight: bold;
  306. line-height: 34px;
  307. color: #fff;
  308. text-align: center;
  309. cursor: pointer;
  310. background: #de4444;
  311. border-radius: 8px;
  312. &:hover {
  313. background: #f76565;
  314. }
  315. &:active {
  316. background: #c43c3c;
  317. }
  318. &.disabled {
  319. color: #fff;
  320. cursor: not-allowed;
  321. background-color: #c8c9cc;
  322. background-image: none;
  323. border-color: #c8c9cc;
  324. }
  325. }
  326. }
  327. .character-target-bg {
  328. position: absolute;
  329. top: 30px;
  330. left: 16px;
  331. width: 256px;
  332. height: 250px;
  333. color: #dedede;
  334. }
  335. .right-strockred {
  336. position: relative;
  337. width: 256px;
  338. height: 256px;
  339. overflow: hidden;
  340. border-radius: 8px;
  341. .img {
  342. position: absolute;
  343. }
  344. }
  345. .footer {
  346. position: absolute;
  347. bottom: 80px;
  348. display: flex;
  349. align-items: center;
  350. justify-content: flex-end;
  351. width: 100%;
  352. padding-right: 40px;
  353. }
  354. }
  355. }
  356. .strockplay {
  357. box-sizing: border-box;
  358. width: 144px;
  359. height: 144px;
  360. overflow: hidden;
  361. border: 2px solid #de4444;
  362. border-radius: 8px;
  363. .strockplayRedInner {
  364. width: 100%;
  365. height: 100%;
  366. }
  367. }
  368. .left-content .footer {
  369. display: flex;
  370. align-items: center;
  371. width: 100%;
  372. cursor: pointer;
  373. .bg-box {
  374. box-sizing: border-box;
  375. display: flex;
  376. align-items: center;
  377. justify-content: space-between;
  378. width: 76px;
  379. height: 32px;
  380. padding: 4px 8px;
  381. font-size: 16px;
  382. line-height: 150%;
  383. color: #000;
  384. text-align: center;
  385. background: #fff;
  386. border: 1px solid rgba(0, 0, 0, 10%);
  387. border-radius: 4px;
  388. img {
  389. width: 24px;
  390. height: 24px;
  391. margin: 0;
  392. }
  393. }
  394. .practice-icon {
  395. height: 36px;
  396. margin-top: 12px;
  397. }
  398. > span {
  399. margin-bottom: 9px;
  400. font-family: 'FZJCGFKTK';
  401. font-size: 24px;
  402. font-weight: 600;
  403. line-height: 34px;
  404. color: #ba7d21;
  405. text-align: center;
  406. }
  407. }
  408. .el-tabs {
  409. width: 100%;
  410. }
  411. </style>
  412. <style lang="scss">
  413. .practiceSingleNPC {
  414. .el-tabs--border-card > .el-tabs__header .el-tabs__item.is-active {
  415. color: #000;
  416. }
  417. .el-tabs--border-card > .el-tabs__header .el-tabs__item:not(.is-disabled):hover {
  418. color: #000;
  419. }
  420. .el-tabs__item,
  421. .el-tabs--border-card > .el-tabs__header .el-tabs__item {
  422. width: 80px;
  423. height: 48px;
  424. font-size: 16px;
  425. font-weight: normal;
  426. line-height: 150%;
  427. line-height: 48px;
  428. color: #000;
  429. text-align: center;
  430. border: none;
  431. }
  432. .el-tabs--border-card > .el-tabs__header {
  433. background: #f3f3f3;
  434. border: none;
  435. }
  436. .el-tabs--border-card > .el-tabs__content {
  437. padding: 0;
  438. }
  439. .el-tab-pane {
  440. display: flex;
  441. }
  442. }
  443. </style>