FreewriteLettle.vue 11 KB

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