cread.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  1. <template>
  2. <div class="cread" v-loading="loading">
  3. <Header v-if="!userID" />
  4. <div class="go-back-box" :class="[userID ? 'go-back-box-user' : '']" v-if="!isPreview">
  5. <a v-if="!userID" class="go-back" :class="[editCardflag ? '' : 'go-back-preview']" @click="goBack">
  6. <i class="el-icon-arrow-left"></i>
  7. 返回
  8. </a>
  9. <template v-if="editCardflag">
  10. <div class="name-box">
  11. <label>卡片名称</label>
  12. <el-input v-model="saveName"></el-input>
  13. </div>
  14. <div class="btn-box">
  15. <el-button small @click="addCard"><i class="el-icon-plus"></i>增加卡片</el-button>
  16. <el-button type="primary" plain small @click="save">结束编辑并保存</el-button>
  17. </div>
  18. </template>
  19. <template v-else>
  20. <h3>{{ saveName }}</h3>
  21. <div class="btn-box">
  22. <el-button small @click="editCardflag = true"><i class="el-icon-edit"></i>编辑</el-button>
  23. <el-button small @click="previewEvent"
  24. ><img src="../../assets/teacherdev/word-eyes.png" alt="" />预览</el-button
  25. >
  26. </div>
  27. </template>
  28. </div>
  29. <div class="content" v-if="!isPreview">
  30. <div v-for="(item, index) in newEditTable" :key="index">
  31. <writeTable
  32. :editCardflag="editCardflag"
  33. :dataConfig="writeTableData"
  34. :data="item"
  35. :pageNumber="index + 1"
  36. :totalNumber="newEditTable.length"
  37. :isPreview="isPreview"
  38. @handleDelItem="handleDelItem"
  39. />
  40. </div>
  41. </div>
  42. <div class="preview_dv" v-if="isPreview" :style="{ top: userID ? '0' : '' }">
  43. <img class="close" src="../../assets/teacherdev/creadCad-close.png" alt="" @click="closepreviewEvent" />
  44. <el-button type="primary" class="print-btn" small @click="download2">打印</el-button>
  45. <div class="preview_main">
  46. <img
  47. class="left"
  48. src="../../assets/teacherdev/creadCad-left.png"
  49. alt=""
  50. @click="changepreviewIndex('remove')"
  51. />
  52. <div class="word_main">
  53. <div class="word_main_table">
  54. <writeTable
  55. :type="typeIndex"
  56. :dataConfig="newEditTable"
  57. :data="newEditTable[previewIndex]"
  58. :pageNumber="previewIndex + 1"
  59. :totalNumber="newEditTable.length"
  60. :isPreview="true"
  61. :showLeft="showLeft"
  62. @changeShowLeft="changeShowLeft"
  63. ref="writeTable"
  64. />
  65. </div>
  66. </div>
  67. <img class="right" src="../../assets/teacherdev/creadCad-right.png" alt="" @click="changepreviewIndex('add')" />
  68. </div>
  69. </div>
  70. </div>
  71. </template>
  72. <script>
  73. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  74. //例如:import 《组件名称》from ‘《组件路径》';
  75. import Header from '@/components/Header';
  76. import { getLogin, LearnWebSI, getHZChineseInfo, getContentFile } from '@/api/api';
  77. import writeTable from './writeTableNew.vue';
  78. import html2canvas from 'html2canvas';
  79. import { jsPDF } from 'jspdf';
  80. import canvg from 'canvg';
  81. import cnchar from 'cnchar';
  82. import 'cnchar-radical';
  83. import FileSaver from 'file-saver';
  84. import htmlDocx from 'html-docx-js/dist/html-docx';
  85. export default {
  86. //import引入的组件需要注入到对象中才能使用
  87. components: {
  88. Header,
  89. writeTable,
  90. },
  91. props: {},
  92. data() {
  93. //这里存放数据
  94. return {
  95. saveName: '',
  96. typeIndex: 0,
  97. loading: false,
  98. writeTableData: null,
  99. isPreview: false,
  100. previewIndex: 0,
  101. saveShow: false,
  102. hzDetailList: null,
  103. userID: this.$route.query.userID ? this.$route.query.userID : '',
  104. editCardflag: true, // 是否编辑卡片
  105. newEditTable: [
  106. {
  107. left: {
  108. fileList: [],
  109. con: '',
  110. },
  111. right: {
  112. definition: '',
  113. collocation: '',
  114. exampleSent: '',
  115. hz_info: [],
  116. pinyin: [],
  117. audio_file: '',
  118. },
  119. },
  120. ],
  121. showLeft: true,
  122. };
  123. },
  124. //计算属性 类似于data概念
  125. computed: {},
  126. //监控data中数据变化
  127. watch: {},
  128. //方法集合
  129. methods: {
  130. addCard() {
  131. this.newEditTable.push({
  132. left: {
  133. fileList: [],
  134. con: '',
  135. },
  136. right: {
  137. definition: '',
  138. collocation: '',
  139. exampleSent: '',
  140. hz_info: [],
  141. pinyin: [],
  142. audio_file: '',
  143. },
  144. });
  145. },
  146. // 删除一条卡片
  147. handleDelItem(index) {
  148. this.newEditTable.splice(index, 1);
  149. },
  150. // 返回上一页
  151. goBack() {
  152. this.$router.push({
  153. path: '/wordcard/table',
  154. });
  155. },
  156. // 保存
  157. save() {
  158. if (!this.saveName.trim()) {
  159. this.$message.warning('请填写卡片名称');
  160. return;
  161. }
  162. this.loading = this.$loading({
  163. lock: true,
  164. text: 'Loading',
  165. spinner: 'el-icon-loading',
  166. background: 'rgba(0, 0, 0, 0.7)',
  167. });
  168. let text = '';
  169. this.newEditTable.forEach((items) => {
  170. text += items.left.con.trim() + '\n';
  171. });
  172. if (this.$route.query.id) {
  173. // 编辑
  174. let Mname = 'tr_tool-wsc_manager-UpdateMyWordSentenceCard';
  175. LearnWebSI(Mname, {
  176. id: this.$route.query.id,
  177. name: this.saveName,
  178. type: this.typeIndex == 0 ? 'WORD' : 'SENTENCE',
  179. text: text,
  180. content: JSON.stringify(this.newEditTable),
  181. update_scope: 0,
  182. })
  183. .then((res) => {
  184. this.loading.close();
  185. this.loading = false;
  186. this.editCardflag = false;
  187. this.$message.success('保存成功');
  188. })
  189. .catch((res) => {
  190. this.loading.close();
  191. this.loading = false;
  192. });
  193. } else {
  194. // 新建
  195. let Mname = 'tr_tool-wsc_manager-CreateMyWordSentenceCard';
  196. LearnWebSI(Mname, {
  197. name: this.saveName,
  198. type: this.typeIndex == 0 ? 'WORD' : 'SENTENCE',
  199. text: text,
  200. content: JSON.stringify(this.newEditTable),
  201. app_user_id: this.userID,
  202. })
  203. .then((res) => {
  204. this.$router.replace({
  205. path: '/wordcard/cread',
  206. query: {
  207. id: res.id,
  208. userID: this.userID,
  209. },
  210. });
  211. this.loading.close();
  212. this.loading = false;
  213. this.editCardflag = false;
  214. this.$message.success('保存成功');
  215. })
  216. .catch((res) => {
  217. this.loading.close();
  218. this.loading = false;
  219. });
  220. }
  221. },
  222. // 字句详情
  223. getdetai() {
  224. this.loading = true;
  225. let Mname = 'tr_tool-wsc_manager-GetWordSentenceCard';
  226. LearnWebSI(Mname, {
  227. id: this.$route.query.id,
  228. })
  229. .then((res) => {
  230. this.saveName = res.name;
  231. this.newEditTable = JSON.parse(res.content);
  232. this.loading = false;
  233. })
  234. .catch((res) => {
  235. this.loading = false;
  236. });
  237. },
  238. // 预览
  239. previewEvent() {
  240. this.previewIndex = 0;
  241. this.isPreview = true;
  242. },
  243. // 关闭预览
  244. closepreviewEvent() {
  245. this.isPreview = false;
  246. },
  247. changepreviewIndex(type) {
  248. if (type == 'add') {
  249. if (this.previewIndex == this.newEditTable.length - 1) {
  250. this.$message.warning('当前已经是最后一页');
  251. return;
  252. }
  253. this.previewIndex++;
  254. } else {
  255. if (this.previewIndex == 0) {
  256. this.$message.warning('当前已经是第一页');
  257. return;
  258. }
  259. this.previewIndex--;
  260. }
  261. this.$refs.writeTable.changeRota();
  262. this.showLeft = true;
  263. this.$forceUpdate();
  264. },
  265. changeShowLeft() {
  266. this.showLeft = !this.showLeft;
  267. },
  268. download2() {
  269. this.$nextTick(() => {
  270. if (this.newEditTable) {
  271. let str = JSON.stringify(this.newEditTable);
  272. localStorage.setItem('newEditTable', str);
  273. this.$router.replace({
  274. path: '/wordcard/printNew',
  275. query: {
  276. userID: this.userID,
  277. id: this.$route.query.id,
  278. },
  279. });
  280. }
  281. });
  282. },
  283. },
  284. //生命周期 - 创建完成(可以访问当前this实例)
  285. created() {},
  286. //生命周期 - 挂载完成(可以访问DOM元素)
  287. mounted() {},
  288. //生命周期-创建之前
  289. beforeCreated() {},
  290. //生命周期-挂载之前
  291. beforeMount() {},
  292. //生命周期-更新之前
  293. beforUpdate() {},
  294. //生命周期-更新之后
  295. updated() {},
  296. //生命周期-销毁之前
  297. beforeDestory() {},
  298. //生命周期-销毁完成
  299. destoryed() {},
  300. //如果页面有keep-alive缓存功能,这个函数会触发
  301. activated() {
  302. if (this.$route.query.cachesType == 'pop') {
  303. this.saveName = '';
  304. this.typeIndex = 0;
  305. this.loading = false;
  306. this.newEditTable = [
  307. {
  308. left: {
  309. fileList: [],
  310. con: '',
  311. },
  312. right: {
  313. definition: '',
  314. collocation: '',
  315. exampleSent: '',
  316. hz_info: [],
  317. pinyin: [],
  318. audio_file: '',
  319. },
  320. },
  321. ];
  322. this.previewIndex = 0;
  323. this.saveShow = false;
  324. this.showLeft = true;
  325. this.editCardflag = true;
  326. this.isPreview = false;
  327. if (this.$route.query.id) {
  328. // 需要请求详情接口
  329. this.getdetai();
  330. }
  331. }
  332. },
  333. };
  334. </script>
  335. <style lang="scss" scoped>
  336. /* @import url(); 引入css类 */
  337. .cread {
  338. min-height: 100%;
  339. position: relative;
  340. background: #f2f2f2;
  341. .go-back-box {
  342. width: 1200px;
  343. display: flex;
  344. border-radius: 8px;
  345. background: #fff;
  346. padding: 8px;
  347. position: fixed;
  348. top: 83px;
  349. left: 50%;
  350. margin-left: -610px;
  351. z-index: 1000;
  352. border: 1px solid rgba(0, 0, 0, 0.15);
  353. &-user {
  354. top: 19px;
  355. }
  356. h3 {
  357. font-size: 24px;
  358. font-weight: 500;
  359. line-height: 150%;
  360. flex: 1;
  361. text-align: center;
  362. }
  363. img {
  364. width: 20px;
  365. margin-right: 6px;
  366. }
  367. .el-button {
  368. padding: 8px 16px;
  369. height: 40px;
  370. line-height: 24px;
  371. }
  372. }
  373. .go-back {
  374. display: flex;
  375. color: #333;
  376. font-size: 24px;
  377. font-weight: 500;
  378. line-height: 36px;
  379. padding: 0 16px 0 0;
  380. align-items: center;
  381. cursor: pointer;
  382. &-preview {
  383. width: 184px;
  384. }
  385. .el-icon-arrow-left {
  386. font-size: 16px;
  387. margin-right: 8px;
  388. }
  389. }
  390. .name-box {
  391. flex: 1;
  392. display: flex;
  393. align-items: center;
  394. label {
  395. color: #4e5969;
  396. font-size: 14px;
  397. font-weight: 400;
  398. line-height: 22px;
  399. margin-right: 16px;
  400. }
  401. .el-input {
  402. width: 227px;
  403. border-radius: 2px;
  404. background: #f2f3f5;
  405. }
  406. }
  407. .btn-box {
  408. display: flex;
  409. i {
  410. margin-right: 8px;
  411. font-size: 16px;
  412. }
  413. }
  414. .content {
  415. padding-top: 88px;
  416. }
  417. }
  418. .preview_dv {
  419. position: absolute;
  420. left: 0;
  421. top: 64px;
  422. width: 100%;
  423. min-height: 100%;
  424. background: #f2f2f2;
  425. > img {
  426. width: 40px;
  427. height: 40px;
  428. cursor: pointer;
  429. position: absolute;
  430. top: 24px;
  431. right: 31px;
  432. }
  433. .print-btn {
  434. cursor: pointer;
  435. position: absolute;
  436. top: 24px;
  437. left: 31px;
  438. }
  439. .preview_main {
  440. padding: 24px 0;
  441. width: 740px;
  442. margin: 0 auto;
  443. display: flex;
  444. align-items: center;
  445. height: 100%;
  446. > div {
  447. margin: 0 24px;
  448. }
  449. img {
  450. width: 48px;
  451. height: 48px;
  452. cursor: pointer;
  453. }
  454. }
  455. }
  456. </style>
  457. <style lang="scss">
  458. .cread {
  459. .name-box {
  460. .el-input__inner {
  461. border-radius: 2px;
  462. background: #f2f3f5;
  463. border: none;
  464. }
  465. }
  466. .btn-box {
  467. .el-button {
  468. span {
  469. display: flex;
  470. align-items: center;
  471. }
  472. }
  473. }
  474. }
  475. </style>