cread.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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-upload
  17. ref="upload"
  18. :action="url"
  19. accept=".xlsx,.xls"
  20. :limit="9999"
  21. :on-exceed="handleExceed"
  22. :on-success="handleSuccess"
  23. :show-file-list="false"
  24. class="btn"
  25. style="margin: 0 8px"
  26. >
  27. <el-button>通过模版导入</el-button>
  28. </el-upload>
  29. <el-button type="primary" plain small @click="save">结束编辑并保存</el-button>
  30. </div>
  31. </template>
  32. <template v-else>
  33. <h3>{{ saveName }}</h3>
  34. <div class="btn-box">
  35. <el-button small @click="editCardflag = true"><i class="el-icon-edit"></i>编辑</el-button>
  36. <el-button small @click="previewEvent"
  37. ><img src="../../assets/teacherdev/word-eyes.png" alt="" />预览</el-button
  38. >
  39. </div>
  40. </template>
  41. </div>
  42. <div class="content" v-if="!isPreview">
  43. <div v-for="(item, index) in newEditTable" :key="index">
  44. <writeTable
  45. :editCardflag="editCardflag"
  46. :dataConfig="writeTableData"
  47. :data="item"
  48. :pageNumber="index + 1"
  49. :totalNumber="newEditTable.length"
  50. :isPreview="isPreview"
  51. @handleDelItem="handleDelItem"
  52. />
  53. </div>
  54. </div>
  55. <div class="preview_dv" v-if="isPreview" :style="{ top: userID ? '0' : '' }">
  56. <img class="close" src="../../assets/teacherdev/creadCad-close.png" alt="" @click="closepreviewEvent" />
  57. <el-button type="primary" class="print-btn" small @click="download2">打印</el-button>
  58. <div class="preview_main">
  59. <img
  60. class="left"
  61. src="../../assets/teacherdev/creadCad-left.png"
  62. alt=""
  63. @click="changepreviewIndex('remove')"
  64. />
  65. <div class="word_main">
  66. <div class="word_main_table">
  67. <writeTable
  68. :type="typeIndex"
  69. :dataConfig="newEditTable"
  70. :data="newEditTable[previewIndex]"
  71. :pageNumber="previewIndex + 1"
  72. :totalNumber="newEditTable.length"
  73. :isPreview="true"
  74. :showLeft="showLeft"
  75. @changeShowLeft="changeShowLeft"
  76. ref="writeTable"
  77. />
  78. </div>
  79. </div>
  80. <img class="right" src="../../assets/teacherdev/creadCad-right.png" alt="" @click="changepreviewIndex('add')" />
  81. </div>
  82. </div>
  83. </div>
  84. </template>
  85. <script>
  86. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  87. //例如:import 《组件名称》from ‘《组件路径》';
  88. import Header from '@/components/Header';
  89. import { getLogin, LearnWebSI, getHZChineseInfo, getContentFile } from '@/api/api';
  90. import writeTable from './writeTableNew.vue';
  91. import { getToken } from '@/utils/auth';
  92. import html2canvas from 'html2canvas';
  93. import { jsPDF } from 'jspdf';
  94. import canvg from 'canvg';
  95. import cnchar from 'cnchar';
  96. import 'cnchar-radical';
  97. import FileSaver from 'file-saver';
  98. import htmlDocx from 'html-docx-js/dist/html-docx';
  99. export default {
  100. //import引入的组件需要注入到对象中才能使用
  101. components: {
  102. Header,
  103. writeTable,
  104. },
  105. props: {},
  106. data() {
  107. //这里存放数据
  108. return {
  109. saveName: '',
  110. typeIndex: 0,
  111. loading: false,
  112. writeTableData: null,
  113. isPreview: false,
  114. previewIndex: 0,
  115. saveShow: false,
  116. hzDetailList: null,
  117. userID: this.$route.query.userID ? this.$route.query.userID : '',
  118. editCardflag: true, // 是否编辑卡片
  119. newEditTable: [
  120. // {
  121. // borderColor: '#243C97',
  122. // fontColor: '#243C97',
  123. // fontAlign: 'left',
  124. // label: '',
  125. // headerCon: '',
  126. // left: {
  127. // fileList: [],
  128. // con: '',
  129. // },
  130. // right: {
  131. // definition: '',
  132. // collocation: '',
  133. // exampleSent: '',
  134. // hz_info: [],
  135. // pinyin: '',
  136. // audio_file: '',
  137. // cixing: '',
  138. // },
  139. // },
  140. ],
  141. showLeft: true,
  142. };
  143. },
  144. //计算属性 类似于data概念
  145. computed: {
  146. url() {
  147. let userInfo = getToken()
  148. ? JSON.parse(getToken())
  149. : sessionStorage.getItem('GCLS_Token_Tc')
  150. ? JSON.parse(sessionStorage.getItem('GCLS_Token_Tc'))
  151. : null;
  152. if (!userInfo) return `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileUpload`;
  153. return `${process.env.VUE_APP_BASE_API}/GCLSFileServer/WebFileUpload?AccessToken=${userInfo.access_token}&SecurityLevel=Mid"`;
  154. },
  155. },
  156. //监控data中数据变化
  157. watch: {},
  158. //方法集合
  159. methods: {
  160. addCard() {
  161. this.newEditTable.push({
  162. borderColor: '#243C97',
  163. fontColor: '#243C97',
  164. fontAlign: 'left',
  165. label: '',
  166. headerCon: '',
  167. left: {
  168. fileList: [],
  169. con: '',
  170. },
  171. right: {
  172. definition: '',
  173. collocation: '',
  174. exampleSent: '',
  175. hz_info: [],
  176. pinyin: '',
  177. audio_file: '',
  178. cixing: '',
  179. },
  180. });
  181. },
  182. // 删除一条卡片
  183. handleDelItem(index) {
  184. this.newEditTable.splice(index, 1);
  185. },
  186. // 返回上一页
  187. goBack() {
  188. this.$router.push({
  189. path: '/wordcard/table',
  190. });
  191. },
  192. // 保存
  193. save() {
  194. if (!this.saveName || !this.saveName.trim()) {
  195. this.$message.warning('请填写卡片名称');
  196. return;
  197. }
  198. this.loading = this.$loading({
  199. lock: true,
  200. text: 'Loading',
  201. spinner: 'el-icon-loading',
  202. background: 'rgba(0, 0, 0, 0.7)',
  203. });
  204. let text = '';
  205. this.newEditTable.forEach((items) => {
  206. text += items.left.con.trim() + '\n';
  207. });
  208. if (this.$route.query.id) {
  209. // 编辑
  210. let Mname = 'tr_tool-wsc_manager-UpdateMyWordSentenceCard';
  211. LearnWebSI(Mname, {
  212. id: this.$route.query.id,
  213. name: this.saveName,
  214. type: this.typeIndex == 0 ? 'WORD' : 'SENTENCE',
  215. text: text,
  216. content: JSON.stringify(this.newEditTable),
  217. update_scope: 0,
  218. })
  219. .then((res) => {
  220. this.loading.close();
  221. this.loading = false;
  222. this.editCardflag = false;
  223. this.$message.success('保存成功');
  224. })
  225. .catch((res) => {
  226. this.loading.close();
  227. this.loading = false;
  228. });
  229. } else {
  230. // 新建
  231. let Mname = 'tr_tool-wsc_manager-CreateMyWordSentenceCard';
  232. LearnWebSI(Mname, {
  233. name: this.saveName,
  234. type: this.typeIndex == 0 ? 'WORD' : 'SENTENCE',
  235. text: text,
  236. content: JSON.stringify(this.newEditTable),
  237. app_user_id: this.userID,
  238. })
  239. .then((res) => {
  240. this.$router.replace({
  241. path: '/wordcard/cread',
  242. query: {
  243. id: res.id,
  244. userID: this.userID,
  245. },
  246. });
  247. this.loading.close();
  248. this.loading = false;
  249. this.editCardflag = false;
  250. this.$message.success('保存成功');
  251. })
  252. .catch((res) => {
  253. this.loading.close();
  254. this.loading = false;
  255. });
  256. }
  257. },
  258. // 字句详情
  259. getdetai() {
  260. this.loading = true;
  261. let Mname = 'tr_tool-wsc_manager-GetWordSentenceCard';
  262. LearnWebSI(Mname, {
  263. id: this.$route.query.id,
  264. })
  265. .then((res) => {
  266. this.saveName = res.name;
  267. this.newEditTable = JSON.parse(res.content);
  268. this.loading = false;
  269. })
  270. .catch((res) => {
  271. this.loading = false;
  272. });
  273. },
  274. // 预览
  275. previewEvent() {
  276. this.previewIndex = 0;
  277. this.showLeft = true;
  278. this.isPreview = true;
  279. },
  280. // 关闭预览
  281. closepreviewEvent() {
  282. this.isPreview = false;
  283. },
  284. changepreviewIndex(type) {
  285. if (type == 'add') {
  286. if (this.previewIndex == this.newEditTable.length - 1) {
  287. this.$message.warning('当前已经是最后一页');
  288. return;
  289. }
  290. this.previewIndex++;
  291. } else {
  292. if (this.previewIndex == 0) {
  293. this.$message.warning('当前已经是第一页');
  294. return;
  295. }
  296. this.previewIndex--;
  297. }
  298. this.$refs.writeTable.changeRota();
  299. this.showLeft = true;
  300. this.$forceUpdate();
  301. },
  302. changeShowLeft() {
  303. this.showLeft = !this.showLeft;
  304. },
  305. download2() {
  306. this.$nextTick(() => {
  307. if (this.newEditTable) {
  308. let str = JSON.stringify(this.newEditTable);
  309. localStorage.setItem('newEditTable', str);
  310. this.$router.replace({
  311. path: '/wordcard/printNew',
  312. query: {
  313. userID: this.userID,
  314. id: this.$route.query.id,
  315. },
  316. });
  317. }
  318. });
  319. },
  320. async handleSuccess(res, file, fileList) {
  321. if (res.status !== 1) {
  322. this.$message.error(res.message);
  323. return;
  324. }
  325. let file_id = file.response.file_info_list[0].file_id;
  326. this.loading = true;
  327. // 通过 fileList 的 response 判断是否已全部完成上传
  328. this.loading = true;
  329. this.$refs.upload.clearFiles();
  330. await LearnWebSI('tr_tool-wsc_manager-ParseWordSentenceCardImportFile', {
  331. file_id: file_id,
  332. })
  333. .then((res) => {
  334. this.loading = false;
  335. this.$message.success('导入成功');
  336. res.content_json_text.forEach((items) => {
  337. if (
  338. items.headerCon ||
  339. items.label ||
  340. items.left.con ||
  341. items.right.cixing ||
  342. items.right.collocation ||
  343. items.right.definition ||
  344. items.right.exampleSent ||
  345. items.right.pinyin
  346. ) {
  347. items.borderColor = '#243C97';
  348. items.fontAlign = 'left';
  349. items.fontColor = '#243C97';
  350. let con = items.left.con.trim();
  351. if (con) {
  352. let MethodName = 'hz_resource_manager-GetMultHZStrokesContent';
  353. let data = {
  354. hz_str: con,
  355. };
  356. getLogin(MethodName, data)
  357. .then((res) => {
  358. this.loading = false;
  359. for (let key in res) {
  360. if (key != 'status' && key != ',' && res[key]) {
  361. res[key] = JSON.parse(res[key]);
  362. }
  363. }
  364. let hzDetailList = res;
  365. let hz_list = [];
  366. con.split('').forEach((items) => {
  367. let res = JSON.parse(JSON.stringify(hzDetailList[items]));
  368. let obj = {
  369. con: items,
  370. hzDetail: {
  371. hz_json: res,
  372. },
  373. };
  374. hz_list.push(obj);
  375. });
  376. items.right.hz_info = hz_list;
  377. let MethodName = 'tool-TextToVoiceFile';
  378. if (con) {
  379. let datas = {
  380. text: con,
  381. };
  382. getLogin(MethodName, datas).then((res) => {
  383. if (res.status === 1) {
  384. items.right.audio_file = res.file_id;
  385. }
  386. });
  387. }
  388. })
  389. .catch(() => {
  390. this.loading = false;
  391. });
  392. }
  393. this.newEditTable.push(items);
  394. }
  395. });
  396. })
  397. .catch((res) => {
  398. this.loading = false;
  399. });
  400. },
  401. handleExceed(files) {
  402. this.$message.warning(`当前限制选择 9999 个文件,本次选择了 ${files.length} 个文件`);
  403. },
  404. },
  405. //生命周期 - 创建完成(可以访问当前this实例)
  406. created() {},
  407. //生命周期 - 挂载完成(可以访问DOM元素)
  408. mounted() {},
  409. //生命周期-创建之前
  410. beforeCreated() {},
  411. //生命周期-挂载之前
  412. beforeMount() {},
  413. //生命周期-更新之前
  414. beforUpdate() {},
  415. //生命周期-更新之后
  416. updated() {},
  417. //生命周期-销毁之前
  418. beforeDestory() {},
  419. //生命周期-销毁完成
  420. destoryed() {},
  421. //如果页面有keep-alive缓存功能,这个函数会触发
  422. activated() {
  423. if (this.$route.query.cachesType == 'pop') {
  424. this.saveName = '';
  425. this.typeIndex = 0;
  426. this.loading = false;
  427. this.newEditTable = [
  428. // {
  429. // borderColor: '#243C97', // 卡片边框颜色
  430. // fontColor: '#243C97', // 字体颜色
  431. // fontAlign: 'left', // 页眉对齐方式
  432. // label: '', // 标签内容
  433. // headerCon: '', // 页眉内容
  434. // left: {
  435. // fileList: [], // 上传文件
  436. // con: '', // 字词卡片内容(即卡片显示的字词)
  437. // },
  438. // right: {
  439. // definition: '', // 释义
  440. // collocation: '', // 搭配
  441. // exampleSent: '', // 例句
  442. // hz_info: [], // 汉字笔顺等内容
  443. // pinyin: '', // 拼音
  444. // audio_file: '', // 字词生成的音频
  445. // cixing: '', // 词性
  446. // },
  447. // },
  448. ];
  449. this.previewIndex = 0;
  450. this.saveShow = false;
  451. this.showLeft = true;
  452. this.editCardflag = true;
  453. this.isPreview = false;
  454. if (this.$route.query.id) {
  455. // 需要请求详情接口
  456. this.getdetai();
  457. }
  458. }
  459. },
  460. };
  461. </script>
  462. <style lang="scss" scoped>
  463. /* @import url(); 引入css类 */
  464. .cread {
  465. min-height: 100%;
  466. position: relative;
  467. background: #f2f2f2;
  468. .go-back-box {
  469. width: 1200px;
  470. display: flex;
  471. border-radius: 8px;
  472. background: #fff;
  473. padding: 8px;
  474. position: fixed;
  475. top: 83px;
  476. left: 50%;
  477. margin-left: -610px;
  478. z-index: 1000;
  479. border: 1px solid rgba(0, 0, 0, 0.15);
  480. &-user {
  481. top: 19px;
  482. }
  483. h3 {
  484. font-size: 24px;
  485. font-weight: 500;
  486. line-height: 150%;
  487. flex: 1;
  488. text-align: center;
  489. }
  490. img {
  491. width: 20px;
  492. margin-right: 6px;
  493. }
  494. .el-button {
  495. padding: 8px 16px;
  496. height: 40px;
  497. line-height: 24px;
  498. }
  499. }
  500. .go-back {
  501. display: flex;
  502. color: #333;
  503. font-size: 24px;
  504. font-weight: 500;
  505. line-height: 36px;
  506. padding: 0 16px 0 0;
  507. align-items: center;
  508. cursor: pointer;
  509. &-preview {
  510. width: 184px;
  511. }
  512. .el-icon-arrow-left {
  513. font-size: 16px;
  514. margin-right: 8px;
  515. }
  516. }
  517. .name-box {
  518. flex: 1;
  519. display: flex;
  520. align-items: center;
  521. label {
  522. color: #4e5969;
  523. font-size: 14px;
  524. font-weight: 400;
  525. line-height: 22px;
  526. margin-right: 16px;
  527. }
  528. .el-input {
  529. width: 227px;
  530. border-radius: 2px;
  531. background: #f2f3f5;
  532. }
  533. }
  534. .btn-box {
  535. display: flex;
  536. i {
  537. margin-right: 8px;
  538. font-size: 16px;
  539. }
  540. }
  541. .content {
  542. padding-top: 88px;
  543. }
  544. }
  545. .preview_dv {
  546. position: absolute;
  547. left: 0;
  548. top: 64px;
  549. width: 100%;
  550. min-height: calc(100% - 64px);
  551. background: #f2f2f2;
  552. > img {
  553. width: 40px;
  554. height: 40px;
  555. cursor: pointer;
  556. position: absolute;
  557. top: 24px;
  558. right: 31px;
  559. }
  560. .print-btn {
  561. cursor: pointer;
  562. position: absolute;
  563. top: 24px;
  564. left: 31px;
  565. }
  566. .preview_main {
  567. padding: 24px 0;
  568. width: 740px;
  569. display: flex;
  570. align-items: center;
  571. height: 450px;
  572. position: absolute;
  573. top: 50%;
  574. margin-top: -225px;
  575. left: 50%;
  576. margin-left: -370px;
  577. > div {
  578. margin: 0 24px;
  579. }
  580. img {
  581. width: 48px;
  582. height: 48px;
  583. cursor: pointer;
  584. }
  585. }
  586. }
  587. </style>
  588. <style lang="scss">
  589. .cread {
  590. .name-box {
  591. .el-input__inner {
  592. border-radius: 2px;
  593. background: #f2f3f5;
  594. border: none;
  595. }
  596. }
  597. .btn-box {
  598. .el-button {
  599. span {
  600. display: flex;
  601. align-items: center;
  602. }
  603. }
  604. }
  605. }
  606. </style>