cread.vue 11 KB

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