Hanzi.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <!-- -->
  2. <template>
  3. <div class="hanzi" dir="ltr" v-if="item">
  4. <div class="left-part">
  5. <div class="strockplay-list">
  6. <div
  7. :class="[
  8. 'strockplay',
  9. conindex < item.new_word.new_word.length - 1 ? 'borderRight' : '',
  10. ]"
  11. v-for="(conItem, conindex) in item.new_word.new_word"
  12. :key="'new_word_' + index + conindex"
  13. >
  14. <Strockplayredline
  15. :key="conItem + index + conindex"
  16. :Book_text="conItem"
  17. :playStorkes="true"
  18. :targetDiv="'bwcHanziIntp' + conItem + index + conindex"
  19. :wordNum="item.new_word.new_word.length"
  20. :themeColor="themeColor"
  21. />
  22. <div
  23. :class="[
  24. 'bwc-line',
  25. themeColor == 'green'
  26. ? 'green-bg'
  27. : themeColor == 'red'
  28. ? 'red-bg'
  29. : 'brown-bg',
  30. ]"
  31. v-if="conindex < item.new_word.new_word.length - 1"
  32. ></div>
  33. </div>
  34. </div>
  35. </div>
  36. <div class="main">
  37. <div class="first-part">
  38. <div class="left">
  39. <span class="pinyin" v-if="item.new_word.pinyin">{{
  40. item.new_word.pinyin
  41. }}</span>
  42. <template v-if="mp3Url">
  43. <Audio :mp3="mp3Url" :themeColor="themeColor" />
  44. </template>
  45. <template v-else-if="item.new_word.audio_file_url">
  46. <AudioLineSentence
  47. :key="'Hanzi' + index"
  48. :mp3="item.new_word.audio_file_url"
  49. :getCurTime="getCurTime"
  50. ref="audioLineSent"
  51. :audioId="'HanziAudioId' + index"
  52. :stopAudio="stopAudio"
  53. :width="120"
  54. :hideSlider="true"
  55. :bg="item.new_word.audio_begin_time"
  56. :ed="item.new_word.audio_end_time"
  57. />
  58. </template>
  59. </div>
  60. </div>
  61. <template
  62. v-if="
  63. item.new_word.definition_list &&
  64. item.new_word.definition_list.length > 0
  65. "
  66. >
  67. <div
  68. class="def-chs"
  69. v-for="(defItem, defIndex) in item.new_word.definition_list"
  70. :key="'defIndex' + defIndex"
  71. v-html="defItem"
  72. ></div>
  73. </template>
  74. <template v-else-if="def_result">
  75. <div class="def-chs">{{ def_result }}</div>
  76. </template>
  77. <div class="resource" v-if="item.new_word.source_courseware_name_path">
  78. {{ item.new_word.source_courseware_name_path }}
  79. </div>
  80. <div class="create_time" v-if="item.create_time">
  81. {{ item.create_time }}
  82. </div>
  83. </div>
  84. <div class="right">
  85. <div class="cancle-coll" @click="cancleColl">
  86. <span class="coll-icon"></span>
  87. <span class="coll-text">{{ $t("Key662") }}</span>
  88. <!-- 取消收藏 -->
  89. </div>
  90. <!-- 查看更多 -->
  91. <span class="look-more" @click="lookMore">{{ $t("Key47") }}</span>
  92. </div>
  93. <div class="practiceBox" v-if="isIntpShow">
  94. <WordPhraseDetail
  95. :collId="item.id"
  96. :closeWord="changeIntpShow"
  97. :themeColor="themeColor"
  98. :currentTreeID="item.goods_id"
  99. :word="item.new_word.new_word"
  100. :detailIndex="index"
  101. />
  102. </div>
  103. </div>
  104. </template>
  105. <script>
  106. import AudioLineSentence from "./AudioLineSentence.vue";
  107. import Strockplayredline from "./Strockplayredline.vue";
  108. import Audio from "./AudioRed.vue";
  109. import { getLearnWebContent } from "@/api/ajax";
  110. import WordPhraseDetail from "./WordPhraseDetail.vue";
  111. export default {
  112. name: "Hanzi",
  113. components: { Strockplayredline, Audio, WordPhraseDetail, AudioLineSentence },
  114. props: ["item", "index"],
  115. data() {
  116. return {
  117. themeColor: "red",
  118. isIntpShow: false,
  119. stopAudio: false,
  120. curTime: 0,
  121. mp3Url: "",
  122. paraphrase: [],
  123. isHasValue2: "",
  124. dataDetail: null,
  125. def_result: "",
  126. };
  127. },
  128. computed: {},
  129. watch: {
  130. item(newVal, oldVal) {
  131. this.initFn();
  132. },
  133. },
  134. //方法集合
  135. methods: {
  136. cancleColl() {
  137. let data = {
  138. id_list: [this.item.id],
  139. };
  140. let MethodName = "order-collection_manager-DeleteMyCollection";
  141. getLearnWebContent(MethodName, data).then((res) => {
  142. // this.$message.success("取消成功!");
  143. this.$message.success(this.$t("Key661"));
  144. this.$emit("getMyCollectionList");
  145. });
  146. },
  147. lookMore() {
  148. this.isIntpShow = true;
  149. },
  150. changeIntpShow() {
  151. this.isIntpShow = false;
  152. },
  153. getCurTime(curTime) {
  154. let _this = this;
  155. _this.curTime = curTime * 1000;
  156. },
  157. // 处理数据
  158. handleChineseDetail() {
  159. let _this = this;
  160. _this.paraphrase = [];
  161. _this.isHasValue2 = "";
  162. _this.def_result = "";
  163. _this.mp3Url = "";
  164. _this.dataDetail.forEach((item) => {
  165. if (item.request.queryType == "entity") {
  166. // 读音
  167. item.response.entity.forEach((items) => {
  168. items.attrs.forEach((itemss) => {
  169. if (itemss.key == "pronunciation") {
  170. // 音频
  171. _this.mp3Url = itemss.objects[0]["@value"]
  172. ? itemss.objects[0]["@value"]
  173. : "";
  174. } else if (itemss.key == "definition") {
  175. // 释义
  176. _this.paraphrase = itemss.objects;
  177. console.log(_this.paraphrase);
  178. for (let i = 0; i < _this.paraphrase.length; i++) {
  179. if (_this.paraphrase[i]["@definitionWithSpell"]) {
  180. _this.isHasValue2 = "definitionWithSpell";
  181. //遍历一个对象
  182. for (let key in _this.paraphrase[i][
  183. "@definitionWithSpell"
  184. ]) {
  185. //遍历key
  186. let def_arr =
  187. _this.paraphrase[i]["@definitionWithSpell"][key];
  188. for (let j = 0; j < def_arr.length; j++) {
  189. if (def_arr[j]) {
  190. _this.def_result = def_arr[j];
  191. return false;
  192. }
  193. }
  194. }
  195. } else if (_this.paraphrase[i]["@definitions"]) {
  196. _this.isHasValue2 = "definitions";
  197. for (
  198. let m = 0;
  199. m < _this.paraphrase[i]["@definitions"].length;
  200. m++
  201. ) {
  202. if (_this.paraphrase[i]["@definitions"][m]) {
  203. _this.def_result =
  204. _this.paraphrase[i]["@definitions"][m];
  205. return false;
  206. }
  207. }
  208. } else {
  209. _this.def_result = _this.paraphrase[i]["@value"];
  210. }
  211. }
  212. }
  213. });
  214. });
  215. }
  216. });
  217. console.log(_this.item.new_word.new_word);
  218. console.log(_this.def_result);
  219. },
  220. initFn() {
  221. let _this = this;
  222. _this.paraphrase = [];
  223. _this.isHasValue2 = "";
  224. _this.def_result = "";
  225. _this.mp3Url = "";
  226. if (_this.item) {
  227. let dict = _this.item.new_word.definition_dictionary_json
  228. ? JSON.parse(_this.item.new_word.definition_dictionary_json)
  229. : null;
  230. _this.dataDetail = dict.data.result;
  231. if (_this.dataDetail) {
  232. _this.handleChineseDetail();
  233. }
  234. }
  235. },
  236. },
  237. //生命周期 - 创建完成(可以访问当前this实例)
  238. created() {},
  239. //生命周期 - 挂载完成(可以访问DOM元素)
  240. mounted() {
  241. this.initFn();
  242. },
  243. beforeCreate() {}, //生命周期 - 创建之前
  244. beforeMount() {}, //生命周期 - 挂载之前
  245. beforeUpdate() {}, //生命周期 - 更新之前
  246. updated() {}, //生命周期 - 更新之后
  247. beforeDestroy() {}, //生命周期 - 销毁之前
  248. destroyed() {}, //生命周期 - 销毁完成
  249. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  250. };
  251. </script>
  252. <style lang='scss' scoped>
  253. //@import url(); 引入公共css类
  254. .hanzi {
  255. width: 100%;
  256. display: flex;
  257. justify-content: flex-start;
  258. align-items: stretch;
  259. .practiceBox {
  260. position: fixed;
  261. width: 100%;
  262. height: 100vh;
  263. left: 0;
  264. top: 0px;
  265. z-index: 9999;
  266. background: rgba(0, 0, 0, 0.19);
  267. box-sizing: border-box;
  268. overflow-y: auto;
  269. padding-bottom: 50px;
  270. &.practiceBoxStrock {
  271. display: flex;
  272. justify-content: center;
  273. align-items: center;
  274. padding-top: 0px;
  275. }
  276. }
  277. .left-part {
  278. min-height: 92px;
  279. max-height: 152px;
  280. background: #f0f0f0;
  281. border-radius: 8px;
  282. display: flex;
  283. justify-content: center;
  284. align-items: center;
  285. margin-right: 16px;
  286. padding: 0 8px;
  287. }
  288. .strockplay-list {
  289. display: flex;
  290. justify-content: flex-start;
  291. align-items: flex-start;
  292. border: 2px solid #de4444;
  293. box-sizing: border-box;
  294. border-radius: 8px;
  295. overflow: hidden;
  296. }
  297. .strockplay {
  298. width: 64px;
  299. height: 64px;
  300. box-sizing: border-box;
  301. &.borderRight {
  302. border-right: 2px #de4444 solid;
  303. }
  304. }
  305. .main {
  306. flex: 1;
  307. .first-part {
  308. clear: both;
  309. overflow: hidden;
  310. display: flex;
  311. justify-content: flex-start;
  312. align-items: center;
  313. margin-bottom: 8px;
  314. .left {
  315. float: left;
  316. display: flex;
  317. justify-content: flex-start;
  318. align-items: center;
  319. .pinyin {
  320. font-size: 24px;
  321. line-height: 32px;
  322. color: rgba(0, 0, 0, 0.85);
  323. margin-right: 4px;
  324. }
  325. }
  326. }
  327. .def-chs {
  328. font-size: 14px;
  329. line-height: 22px;
  330. color: rgba(0, 0, 0, 0.85);
  331. margin-bottom: 8px;
  332. opacity: 0.5;
  333. max-width: 560px;
  334. }
  335. .def-en {
  336. font-size: 14px;
  337. line-height: 22px;
  338. color: rgba(0, 0, 0, 0.85);
  339. margin-bottom: 8px;
  340. opacity: 0.5;
  341. }
  342. .resource {
  343. font-size: 14px;
  344. line-height: 22px;
  345. color: #2c2c2c;
  346. opacity: 0.5;
  347. margin-bottom: 8px;
  348. }
  349. .create_time {
  350. font-size: 14px;
  351. line-height: 22px;
  352. color: #2c2c2c;
  353. opacity: 0.5;
  354. }
  355. }
  356. .right {
  357. display: flex;
  358. flex-direction: column;
  359. justify-content: space-between;
  360. align-items: center;
  361. height: 100%;
  362. .cancle-coll {
  363. float: right;
  364. padding: 0 12px;
  365. height: 32px;
  366. display: flex;
  367. justify-content: flex-start;
  368. align-items: center;
  369. cursor: pointer;
  370. border: 1px solid rgba(0, 0, 0, 0.1);
  371. box-sizing: border-box;
  372. border-radius: 4px;
  373. > .coll-icon {
  374. width: 16px;
  375. height: 16px;
  376. background: url("../../assets/starfill-16-normal-red.png") no-repeat
  377. left top;
  378. background-size: 100% 100%;
  379. margin-right: 4px;
  380. }
  381. > .coll-text {
  382. font-size: 14px;
  383. line-height: 22px;
  384. color: #000000;
  385. }
  386. }
  387. .look-more {
  388. font-size: 14px;
  389. line-height: 22px;
  390. color: rgba(0, 0, 0, 0.85);
  391. opacity: 0.5;
  392. cursor: pointer;
  393. }
  394. }
  395. }
  396. </style>