index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. <!-- -->
  2. <template>
  3. <div class="NPC-ArticleView NPC-ArticleView-container">
  4. <div class="ArticleView-header">
  5. <template v-if="curQue.checkList.indexOf(1) > -1">
  6. <el-switch
  7. style="display: block"
  8. v-model="showPhrases"
  9. :active-color="activeColor"
  10. inactive-color="rgba(0,0,0,0.1)"
  11. active-text=""
  12. inactive-text="本课生词"
  13. @change="handleSwitchChange('showPractice', 'showWord')"
  14. >
  15. </el-switch>
  16. </template>
  17. <template v-if="curQue.checkList.indexOf(2) > -1">
  18. <el-switch
  19. style="display: block"
  20. v-model="showPractice"
  21. :active-color="activeColor"
  22. inactive-color="rgba(0,0,0,0.1)"
  23. active-text=""
  24. inactive-text="语音练习"
  25. @change="handleSwitchChange('showPhrases', 'showWord')"
  26. >
  27. </el-switch>
  28. </template>
  29. <template v-if="curQue.checkList.indexOf(3) > -1">
  30. <el-switch
  31. style="display: block"
  32. v-model="showWord"
  33. :active-color="activeColor"
  34. inactive-color="rgba(0,0,0,0.1)"
  35. active-text=""
  36. inactive-text="取词"
  37. @change="handleSwitchChange('showPhrases', 'showPractice')"
  38. >
  39. </el-switch>
  40. </template>
  41. <!-- <div class="setting-fontsize">
  42. <a @click="handleFontsize('-')"
  43. ><img src="../../../../assets/newImage/common/btn-reduce.png"
  44. /></a>
  45. <img src="../../../../assets/newImage/common/font-size.png" />
  46. <a @click="handleFontsize('+')"
  47. ><img src="../../../../assets/newImage/common/btn-increase.png"
  48. /></a>
  49. </div> -->
  50. </div>
  51. <div class="ArticleView-body" ref="ArticleViewbody">
  52. <NormalModelChs
  53. :curQue="curQue"
  54. :titleFontsize="titleFontsize"
  55. :wordFontsize="wordFontsize"
  56. :bodyLeft="bodyLeft"
  57. :bodyWidth="bodyWidth"
  58. :themeColor="themeColor"
  59. :noFont="noFont"
  60. v-if="!showPhrases && !showPractice && !showWord"
  61. :currentTreeID="currentTreeID"
  62. :config="config"
  63. @changeConfig="changeConfig"
  64. />
  65. <PhraseModel
  66. :curQue="curQue"
  67. :titleFontsize="titleFontsize"
  68. :wordFontsize="wordFontsize"
  69. :NNPENewWordList="NNPENewWordList"
  70. :themeColor="themeColor"
  71. :noFont="noFont"
  72. :currentTreeID="currentTreeID"
  73. :bodyLeft="bodyLeft"
  74. v-if="showPhrases"
  75. :config="config"
  76. @changeConfig="changeConfig"
  77. />
  78. <Practice
  79. :curQue="curQue"
  80. :titleFontsize="titleFontsize"
  81. :wordFontsize="wordFontsize"
  82. :themeColor="themeColor"
  83. :noFont="noFont"
  84. :NNPENewWordList="NNPENewWordList"
  85. :currentTreeID="currentTreeID"
  86. v-if="showPractice"
  87. :config="config"
  88. @changeConfig="changeConfig"
  89. />
  90. <WordModel
  91. :curQue="curQue"
  92. :titleFontsize="titleFontsize"
  93. :wordFontsize="wordFontsize"
  94. :bodyLeft="bodyLeft"
  95. :bodyWidth="bodyWidth"
  96. :NNPENewWordList="NNPENewWordList"
  97. :themeColor="themeColor"
  98. :noFont="noFont"
  99. :currentTreeID="currentTreeID"
  100. v-if="showWord"
  101. :config="config"
  102. @changeConfig="changeConfig"
  103. />
  104. </div>
  105. </div>
  106. </template>
  107. <script>
  108. import PhraseModel from "./PhraseModelChs.vue";
  109. import NormalModelChs from "./NormalModelChs.vue";
  110. import Practice from "./Practicechs.vue"; // 语音练习模式
  111. import WordModel from "./WordModelChs.vue"; // 语音练习模式
  112. export default {
  113. name: "ArticleViewChs",
  114. props: ["curQue", "NNPENewWordList", "themeColor", "currentTreeID"],
  115. components: { NormalModelChs, Practice, WordModel, PhraseModel },
  116. data() {
  117. return {
  118. showPreview: true, // 全文预览
  119. showPhrases: false, // 显示单词和短语
  120. showPractice: false, // 语音练习
  121. showWord: false, // 取词
  122. titleFontsize: 20, // 标题字号初始值
  123. wordFontsize: 16, // 文章内容字号初始值
  124. bodyLeft: 0,
  125. bodyWidth: 0,
  126. noFont: ["~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "/"],
  127. config: {
  128. isShowEN: false,
  129. isHasEN: false,
  130. isShowPY: false,
  131. isHasPY: false,
  132. },
  133. };
  134. },
  135. computed: {
  136. activeColor: function () {
  137. let color = "";
  138. if (this.themeColor == "red") {
  139. color = "#DE4444";
  140. } else if (this.themeColor == "green") {
  141. color = "#24B99E";
  142. } else if (this.themeColor == "brown") {
  143. color = "#BD8865";
  144. }
  145. return color;
  146. },
  147. },
  148. watch: {
  149. currentTreeID: {
  150. handler: function () {
  151. this.showPreview = true; // 全文预览
  152. this.showPhrases = false; // 显示单词和短语
  153. this.showPractice = false; // 语音练习
  154. this.showWord = false; // 取词
  155. },
  156. deep: true,
  157. },
  158. },
  159. //方法集合
  160. methods: {
  161. changeConfig(obj) {
  162. this.config[obj] = !this.config[obj];
  163. },
  164. // 处理字体大小
  165. handleFontsize(symbol) {
  166. if (symbol == "+") {
  167. if (this.wordFontsize < 24) {
  168. this.titleFontsize = this.titleFontsize + 2;
  169. this.wordFontsize = this.wordFontsize + 2;
  170. }
  171. } else if (symbol == "-") {
  172. if (this.wordFontsize > 12) {
  173. this.titleFontsize = this.titleFontsize - 2;
  174. this.wordFontsize = this.wordFontsize - 2;
  175. }
  176. }
  177. },
  178. // 切换开关
  179. handleSwitchChange(obj1, obj2) {
  180. this[obj1] = false;
  181. this[obj2] = false;
  182. this.showPreview = false;
  183. },
  184. handleObj(list) {
  185. let pinyin = "";
  186. list.forEach((item) => {
  187. pinyin += item.pinyin;
  188. });
  189. return pinyin;
  190. },
  191. },
  192. //生命周期 - 创建完成(可以访问当前this实例)
  193. created() {},
  194. //生命周期 - 挂载完成(可以访问DOM元素)
  195. mounted() {
  196. console.log("我是文章预览");
  197. console.log(this.curQue);
  198. this.$nextTick(() => {
  199. this.bodyLeft = this.$refs.ArticleViewbody.getBoundingClientRect().left;
  200. });
  201. for (let i = 0; i < this.curQue.detail.length; i++) {
  202. let enStr = this.curQue.detail[i].sentencesEn
  203. ? this.curQue.detail[i].sentencesEn.join("")
  204. : "";
  205. if (enStr) {
  206. this.config.isShowEN = true;
  207. this.config.isHasEN = true;
  208. }
  209. let pinyin = this.handleObj(this.curQue.detail[i].wordsList);
  210. if (pinyin) {
  211. this.config.isShowPY = true;
  212. this.config.isHasPY = true;
  213. }
  214. if (enStr && pinyin) {
  215. break;
  216. }
  217. }
  218. },
  219. beforeCreate() {}, //生命周期 - 创建之前
  220. beforeMount() {}, //生命周期 - 挂载之前
  221. beforeUpdate() {}, //生命周期 - 更新之前
  222. updated() {}, //生命周期 - 更新之后
  223. beforeDestroy() {}, //生命周期 - 销毁之前
  224. destroyed() {}, //生命周期 - 销毁完成
  225. activated() {}, //如果页面有keep-alive缓存功能,这个函数会触发
  226. };
  227. </script>
  228. <style lang='scss' scoped>
  229. //@import url(); 引入公共css类
  230. .NPC-ArticleView {
  231. width: 100%;
  232. &.NPC-ArticleView-container {
  233. margin-bottom: 24px;
  234. }
  235. .ArticleView-header {
  236. display: flex;
  237. justify-content: flex-end;
  238. align-items: center;
  239. margin-bottom: 16px;
  240. .setting-fontsize {
  241. display: flex;
  242. margin-left: 24px;
  243. a {
  244. border: 1px solid rgba(0, 0, 0, 0.1);
  245. box-sizing: border-box;
  246. border-radius: 4px;
  247. display: block;
  248. height: 24px;
  249. width: 24px;
  250. }
  251. img {
  252. width: 100%;
  253. }
  254. > img {
  255. margin: 0 8px;
  256. width: 24px;
  257. }
  258. }
  259. }
  260. .ArticleView-body {
  261. border: 1px solid rgba(0, 0, 0, 0.1);
  262. box-sizing: border-box;
  263. border-radius: 8px;
  264. background: #fff;
  265. box-sizing: border-box;
  266. .aduioLine-box {
  267. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  268. width: 100%;
  269. }
  270. }
  271. }
  272. </style>
  273. <style lang="scss">
  274. .NPC-ArticleView {
  275. .ArticleView-header {
  276. .el-switch {
  277. margin-left: 24px;
  278. }
  279. .el-switch__core {
  280. width: 44px !important;
  281. height: 24px;
  282. border-radius: 20px;
  283. }
  284. .el-switch__core:after {
  285. top: 3px;
  286. left: 3px;
  287. }
  288. .el-switch.is-checked .el-switch__core::after {
  289. left: 100%;
  290. margin-left: -19px;
  291. }
  292. .el-switch__label {
  293. color: #000000;
  294. }
  295. .el-switch__label.is-active {
  296. color: rgba($color: #000000, $alpha: 0.3);
  297. }
  298. .el-switch__label--left {
  299. margin-right: 8px;
  300. }
  301. }
  302. }
  303. .ArticleView-body {
  304. .aduioLine-box {
  305. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  306. width: 100%;
  307. }
  308. }
  309. </style>