NewWordList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. <template>
  2. <div v-if="wordList.length>0">
  3. <ul>
  4. <li v-for="(itemW,indexW) in wordList" :key="indexW" :class="['li-'+colorObj.type]">
  5. <svg-icon v-if="itemW.hasVoice&&!voiceSrc||itemW.hasVoice&&activeIndex!==indexW" icon-class="voice" className="icon-voice" @click="handlePlayVoice(itemW,indexW)"></svg-icon>
  6. <img v-if="itemW.hasVoice&&voiceSrc&&activeIndex===indexW" :src="voiceSrc" class="icon-voice" />
  7. <svg-icon v-if="!itemW.hasVoice" icon-class="voice" className="icon-voice" style="color:rgba(78, 89, 105, 0.3)"></svg-icon>
  8. <div class="word-info">
  9. <div class="word-info-top">
  10. <b class="word" @click="showWord(itemW)" :style="{color:colorObj.newWordColor}">{{itemW.word}}</b>
  11. <span class="symbol" :style="{color:colorObj.newWordOtherColor}">{{itemW.symbol}}</span>
  12. <span class="star" v-if="itemW.rate">
  13. <svg-icon icon-class="star-filled" v-for="(itemS,indexS) in itemW.rate" :key="indexS" :style="{color:colorObj.newWordStar}"></svg-icon>
  14. </span>
  15. <div class="para-list">
  16. <div class="para" v-for="(itemP,indexP) in itemW.paraList" :key="indexP">
  17. <span class="cixing" :style="{color:colorObj.newWordOtherColor}">{{itemP.cixing}}</span>
  18. <span class="shiyi" :style="{color:colorObj.newWordOtherColor}">{{itemP.para}}</span>
  19. </div>
  20. </div>
  21. </div>
  22. </div>
  23. <label class="word-type" :style="{color:colorObj.newWordType[itemW.type]?colorObj.newWordType[itemW.type].color:'',background:colorObj.newWordType[itemW.type]?olorObj.newWordType[itemW.type].bg:''}">{{itemW.typeCn}}</label>
  24. <svg-icon icon-class="like-line" className="icon-like" v-if="!itemW.collect" @click="handleCollect(itemW)"></svg-icon>
  25. <svg-icon icon-class="like" className="icon-like active" v-else @click="handleCollect(itemW)"></svg-icon>
  26. <!-- <i class="el-icon-arrow-right"></i> -->
  27. </li>
  28. </ul>
  29. <el-dialog
  30. :visible.sync="wordcardShow"
  31. :show-close="false"
  32. :close-on-click-modal="false"
  33. width="570px"
  34. class="login-dialog"
  35. v-if="wordcardShow">
  36. <WordCard @closeWord="closeWord" />
  37. </el-dialog>
  38. </div>
  39. </template>
  40. <script>
  41. //这里可以导入其它文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  42. //例如:import 《组件名称》from ‘《组件路径》';
  43. import { getLogin } from "@/api/ajax";
  44. import WordCard from "../../personalCenter/components/WordCard.vue"
  45. export default {
  46. //import引入的组件需要注入到对象中才能使用
  47. components: {WordCard},
  48. props: ["list","colorObj"],
  49. data() {
  50. //这里存放数据
  51. return {
  52. wordcardShow: false, // 词汇卡片flag
  53. wordList: [],
  54. audio: new Audio(),
  55. voiceSrc: "",
  56. voicePauseSrc: '',
  57. voicePlaySrc: require("../../../assets/voice-play-gray.png"),
  58. activeIndex: null
  59. }
  60. },
  61. //计算属性 类似于data概念
  62. computed: {},
  63. //监控data中数据变化
  64. watch: {
  65. list:{
  66. handler(val, oldVal) {
  67. const _this = this;
  68. if (val) {
  69. this.handleData()
  70. }
  71. },
  72. // 深度观察监听
  73. deep: true,
  74. },
  75. },
  76. //方法集合
  77. methods: {
  78. // 收藏
  79. handleCollect(item){
  80. if(item.collect){
  81. let MethodName = "/ShopServer/Client/CollectManager/CancelCollect_Word";
  82. let data = {
  83. word: item.word,
  84. }
  85. getLogin(MethodName, data)
  86. .then((res) => {
  87. this.loading = false
  88. if(res.status===1){
  89. item.collect = false
  90. this.$forceUpdate()
  91. this.$message({
  92. message: "取消收藏",
  93. type: "success",
  94. });
  95. }
  96. })
  97. .catch(() => {
  98. });
  99. }else{
  100. let MethodName = "/ShopServer/Client/CollectManager/AddCollect_Word";
  101. let data = {
  102. word: item.word,
  103. pinyin: item.symbol,
  104. explain: JSON.stringify(item.paraList),
  105. is_new: "true",
  106. audio_file_id: item.word_explain&&item.word_explain.ph_mp3_id?item.word_explain.ph_mp3_id:'',
  107. audio_file_url: item.word_explain&&item.word_explain.ph_file_url?item.word_explain.ph_file_url:'',
  108. article_id: this.$route.query.id,
  109. word_id: item.id
  110. }
  111. getLogin(MethodName, data)
  112. .then((res) => {
  113. this.loading = false
  114. this.$forceUpdate()
  115. if(res.status===1){
  116. item.collect = true
  117. this.$message({
  118. message: "收藏成功",
  119. type: "success",
  120. });
  121. }
  122. })
  123. .catch(() => {
  124. });
  125. }
  126. },
  127. // 查看单词卡片
  128. showWord(obj){
  129. this.wordcardShow = true
  130. },
  131. // 关闭单词卡片
  132. closeWord(){
  133. this.wordcardShow = false
  134. },
  135. async handlePlayVoice(item,index) {
  136. let _this = this;
  137. let url = ''
  138. if(item.originalObj.word_explain.ph_mp3_id){
  139. await getLogin('/FileServer/GetFileInfo', {file_id:item.originalObj.word_explain.ph_mp3_id})
  140. .then((res) => {
  141. if(res.status===1){
  142. url = res.file_url
  143. }
  144. })
  145. }else if(item.originalObj.word_explain.ph_file_url){
  146. url = item.originalObj.word_explain.ph_file_url
  147. }
  148. if (!url) {
  149. return;
  150. }
  151. // if (!this.audio.paused) {
  152. // this.audio.pause();
  153. // } else
  154. {
  155. _this.audio.pause();
  156. _this.audio.load();
  157. _this.audio.src = url;
  158. _this.audio.loop = false;
  159. _this.audio.play();
  160. _this.activeIndex = index
  161. }
  162. },
  163. handleData(){
  164. this.wordList = []
  165. let wordList = JSON.parse(JSON.stringify(this.list))
  166. wordList.forEach(items => {
  167. let obj = {
  168. src: items.ph_file_url?items.ph_file_url:'',
  169. word: items.word_name,
  170. symbol: items.word_explain.ph?items.word_explain.ph:'',
  171. paraList: items.word_explain.word_para_list,
  172. type: items.word_explain.vl_level?items.word_explain.vl_level:'',
  173. typeCn: items.word_explain.vl_level_name?items.word_explain.vl_level_name:'',
  174. rate: items.word_explain.star?items.word_explain.star:null,
  175. originalObj: items,
  176. hasVoice: items.word_explain.ph_mp3_id||items.word_explain.ph_file_url?true:false,
  177. id: items.id
  178. }
  179. this.wordList.push(obj)
  180. });
  181. }
  182. },
  183. //生命周期 - 创建完成(可以访问当前this实例)
  184. created() {
  185. this.handleData()
  186. },
  187. //生命周期 - 挂载完成(可以访问DOM元素)
  188. mounted() {
  189. let _this = this;
  190. _this.voiceSrc = _this.voicePauseSrc;
  191. _this.audio.addEventListener("play", function () {
  192. // console.log("播放");
  193. _this.voiceSrc = _this.voicePlaySrc;
  194. });
  195. _this.audio.addEventListener("pause", function () {
  196. _this.voiceSrc = _this.voicePauseSrc;
  197. });
  198. _this.audio.addEventListener("ended", function () {
  199. // console.log("停止");
  200. _this.voiceSrc = _this.voicePauseSrc;
  201. });
  202. },
  203. //生命周期-创建之前
  204. beforeCreated() { },
  205. //生命周期-挂载之前
  206. beforeMount() { },
  207. //生命周期-更新之前
  208. beforUpdate() { },
  209. //生命周期-更新之后
  210. updated() { },
  211. //生命周期-销毁之前
  212. beforeDestory() { },
  213. //生命周期-销毁完成
  214. destoryed() { },
  215. //如果页面有keep-alive缓存功能,这个函数会触发
  216. activated() { }
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. /* @import url(); 引入css类 */
  221. ul{
  222. li{
  223. padding: 8px;
  224. display: flex;
  225. margin: 1px 0;
  226. border-radius: 4px;
  227. &:hover{
  228. background: #FFFFFF;
  229. }
  230. &.li-darkGreen{
  231. &:hover{
  232. background: #ECEFED;
  233. }
  234. }
  235. &.li-darkBlue{
  236. &:hover{
  237. background: #4E5969;
  238. }
  239. }
  240. &.li-armyGreen{
  241. &:hover{
  242. background: #66736D;
  243. }
  244. }
  245. .icon-voice{
  246. width: 24px;
  247. height: 24px;
  248. padding: 4px;
  249. color: #4E5969;
  250. margin-right: 8px;
  251. cursor: pointer;
  252. }
  253. .xuhao{
  254. min-width: 22px;
  255. display: block;
  256. font-size: 14px;
  257. line-height: 22px;
  258. color: #2F3742;
  259. }
  260. .word-info{
  261. flex: 1;
  262. }
  263. .sentence{
  264. font-size: 14px;
  265. line-height: 22px;
  266. color: #2F3742;
  267. }
  268. .icon-like{
  269. // color: #F2555A;
  270. width: 24px;
  271. height: 24px;
  272. padding: 4px;
  273. margin: 0 0 0 8px;
  274. cursor: pointer;
  275. &.active{
  276. color: #F2555A;
  277. }
  278. }
  279. .word-type{
  280. padding: 1px 8px;
  281. border-radius: 2px;
  282. font-weight: 500;
  283. font-size: 14px;
  284. line-height: 22px;
  285. height: 26px;
  286. }
  287. .el-icon-arrow-right{
  288. width: 24px;
  289. height: 24px;
  290. color: #929CA8;
  291. text-align: center;
  292. line-height: 24px;
  293. cursor: pointer;
  294. }
  295. .word-info-top{
  296. display: flex;
  297. .word{
  298. font-weight: 700;
  299. font-size: 14px;
  300. line-height: 22px;
  301. color: #175DFF;
  302. margin-right: 8px;
  303. font-family: 'Arial';
  304. cursor: pointer;
  305. }
  306. .phrase{
  307. font-weight: 500;
  308. font-size: 14px;
  309. line-height: 22px;
  310. color: #ED5F00;
  311. }
  312. .symbol{
  313. font-size: 14px;
  314. line-height: 22px;
  315. color: #4E5969;
  316. margin-right: 8px;
  317. font-family: 'Arial';
  318. }
  319. .star{
  320. margin-right: 8px;
  321. line-height: 20px;
  322. }
  323. .para-list{
  324. flex: 1;
  325. .para{
  326. display: flex;
  327. font-size: 14px;
  328. line-height: 22px;
  329. color: #4E5969;
  330. margin-bottom: 4px;
  331. .cixing{
  332. margin-right: 4px;
  333. }
  334. }
  335. }
  336. }
  337. .word-info-bottom{
  338. font-size: 12px;
  339. line-height: 20px;
  340. color: #929CA8;
  341. margin: 4px 8px 0 0;
  342. span{
  343. margin-right: 8px;
  344. }
  345. }
  346. }
  347. }
  348. </style>