bookView.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <div class="container">
  3. <div class="book-content-inner">
  4. <div
  5. id="content-tree"
  6. :class="[fullTree ? 'content-tree-full' : 'content-tree']"
  7. >
  8. <h2 class="catelog">目录</h2>
  9. <div style="padding-left: 8px">
  10. <TreeView
  11. ref="treeView"
  12. :book-id="bookId"
  13. :change-id="changeId"
  14. :changeTreeData="changeTreeData"
  15. />
  16. </div>
  17. </div>
  18. <div id="data-screen" class="inner">
  19. <!-- 显示答案按钮 -->
  20. <!-- <a v-if="chapterId" :class="['answerShow',isAnswerShow?'answerShowTrue':'']" @click="handleAnswerShow">显示答案</a> -->
  21. <!-- <a class="edit-btn" @click="handleEdit">编辑</a> -->
  22. <div v-if="chapterId" class="title-box">
  23. <img
  24. v-if="!treeFlag"
  25. src="../assets/common/icon-view-back.png"
  26. @click="treeShow"
  27. />
  28. <img
  29. v-if="!treeFlag"
  30. :src="
  31. fullTree
  32. ? require('../assets/common/icon-treelist-gray.png')
  33. : require('../assets/common/icon-treelist.png')
  34. "
  35. @click="chooseCourseware"
  36. />
  37. <h2 class="title">{{ chapterName }}</h2>
  38. <!-- <el-switch
  39. v-if="!treeFlag"
  40. v-model="switchvalue"
  41. active-color="#FF9900"
  42. active-text
  43. inactive-text="生词模式"
  44. /> -->
  45. </div>
  46. <template v-if="category == 'oc' || !category">
  47. <Preview
  48. v-if="chapterId && context"
  49. ref="previewAnswer"
  50. :context="context"
  51. :bookAnswerContent="bookAnswerContent"
  52. bookclientwidth="900"
  53. :TaskModel="TaskModel"
  54. @handleBookUserAnswer="handleBookUserAnswer"
  55. />
  56. </template>
  57. <template v-if="category == 'NPC'">
  58. <Booknpc
  59. v-if="chapterId && context"
  60. ref="previewAnswer"
  61. :context="context"
  62. :currentTreeID="chapterId"
  63. :FatherTreeData="FatherTreeData"
  64. :change-id="changeId"
  65. :themeColor="themeColor"
  66. :isShowTitle="true"
  67. />
  68. </template>
  69. </div>
  70. <a
  71. v-if="chapterId && treeFlag"
  72. class="screen-full"
  73. @click="fullScreen()"
  74. />
  75. </div>
  76. <!-- <Preview :context="context" :queIndex="queIndex" /> -->
  77. </div>
  78. </template>
  79. <script>
  80. import TreeView from "@/components/inputModules/common/TreeView";
  81. import { getContent } from "@/api/ajax";
  82. import Cookies from "js-cookie";
  83. // import Preview from '@/componentsAnswer/PreviewAnswer.vue'
  84. import Preview from "@/components/Preview";
  85. export default {
  86. name: "CourseView",
  87. components: {
  88. TreeView,
  89. Preview,
  90. },
  91. props: ["bookId", "bookIsBuy"],
  92. data() {
  93. return {
  94. chapterId: "",
  95. chapterName: "",
  96. fullscreen: false, // 控制全屏
  97. context: null,
  98. question: null, // 选择的模板题型
  99. queIndex: "",
  100. treeFlag: true, // tree是否显示
  101. switchvalue: true, // 生词模式
  102. isAnswerShow: false, // 是否显示答案
  103. bookAnswerContent: "[]",
  104. TaskModel: "",
  105. fullTree: false, // 全屏模式下树是否显示
  106. category: "",
  107. FatherTreeData: null,
  108. themeColor: "",
  109. };
  110. },
  111. mounted() {
  112. // const _this = this
  113. // _this.bookId = this.$route.query.bookId
  114. },
  115. methods: {
  116. changeTreeData(val) {
  117. this.FatherTreeData = JSON.parse(JSON.stringify(val));
  118. },
  119. changeId(id, name, free) {
  120. // if (
  121. // this.bookIsBuy == "true" ||
  122. // (this.bookIsBuy == "false" && free == "true")
  123. // ) {
  124. const _this = this;
  125. _this.chapterId = id;
  126. _this.chapterName = name;
  127. _this.isAnswerShow = false;
  128. _this.onGetData();
  129. if (!_this.treeFlag) {
  130. _this.fullTree = false;
  131. document.getElementById("content-tree").style.display = "none";
  132. }
  133. // } else {
  134. // this.chapterId = "";
  135. // this.chapterName = "";
  136. // this.context = null;
  137. // this.$message(
  138. // {
  139. // type: "warning",
  140. // message: "您还没有购买此教材,请购买后查看!",
  141. // },
  142. // 2000
  143. // );
  144. // }
  145. },
  146. // 点击全屏展示 隐藏tree
  147. fullScreen() {
  148. this.treeFlag = false;
  149. document.getElementById("content-tree").style.display = "none";
  150. this.$emit("bookdetailShow", false);
  151. },
  152. treeShow() {
  153. this.treeFlag = true;
  154. this.fullTree = false;
  155. document.getElementById("content-tree").style.display = "block";
  156. this.$emit("bookdetailShow", true);
  157. },
  158. // 获取预览数据
  159. onGetData() {
  160. const _this = this;
  161. const MethodName = "book-courseware_manager-GetCoursewareContent_View";
  162. const data = {
  163. id: _this.chapterId,
  164. };
  165. getContent(MethodName, data).then((res) => {
  166. console.log(res);
  167. this.category = res.category;
  168. this.themeColor = res.book_theme_color;
  169. if (res.content) {
  170. const _this = this;
  171. if (!this.category || this.category == "oc") {
  172. _this.context = {
  173. id: _this.chapterId,
  174. ui_type: JSON.parse(res.content).question
  175. ? JSON.parse(res.content).question.ui_type
  176. : "",
  177. sort_number: 1,
  178. content: JSON.parse(res.content),
  179. };
  180. } else if (this.category == "NPC") {
  181. _this.context = JSON.parse(res.content);
  182. }
  183. } else {
  184. const _this = this;
  185. _this.context = null;
  186. }
  187. });
  188. },
  189. // 显示或隐藏答案
  190. handleAnswerShow() {
  191. this.isAnswerShow = !this.isAnswerShow;
  192. this.$refs.previewAnswer.bookAnswerShow(this.isAnswerShow);
  193. },
  194. // 得到用户答题答案
  195. handleBookUserAnswer(data) {
  196. console.log(data);
  197. },
  198. // 悬浮树隐藏显示
  199. chooseCourseware() {
  200. this.fullTree = !this.fullTree;
  201. if (this.fullTree) {
  202. document.getElementById("content-tree").style.display = "block";
  203. } else {
  204. document.getElementById("content-tree").style.display = "none";
  205. }
  206. },
  207. },
  208. };
  209. </script>
  210. <style lang="scss" scoped>
  211. .container {
  212. width: 100%;
  213. height: auto;
  214. .catelog {
  215. padding: 24px 40px 16px 40px;
  216. font-weight: 600;
  217. font-size: 24px;
  218. line-height: 150%;
  219. color: #000000;
  220. margin: 0;
  221. }
  222. .book-content-inner {
  223. background: #fff;
  224. width: 100%;
  225. height: 700px;
  226. overflow: auto;
  227. display: flex;
  228. justify-content: flex-start;
  229. align-items: flex-start;
  230. position: relative;
  231. &-tree {
  232. width: 340px;
  233. height: 100%;
  234. overflow: auto;
  235. padding: 20px 0px;
  236. border-right: 1px solid #d9d9d9;
  237. }
  238. .content-tree {
  239. width: 320px;
  240. border-right: 1px solid #d9d9d9;
  241. max-height: 700px;
  242. overflow: auto;
  243. }
  244. .content-tree-full {
  245. position: fixed;
  246. top: 100px;
  247. left: 152px;
  248. max-height: 588px;
  249. overflow: auto;
  250. z-index: 999;
  251. background: #fff;
  252. box-shadow: 0px 2px 8px rgba(0, 0, 0, 0.25);
  253. border-radius: 4px;
  254. }
  255. .inner {
  256. width: 1000px;
  257. max-height: 700px;
  258. overflow: auto;
  259. flex: 1;
  260. margin: 0 auto;
  261. box-sizing: border-box;
  262. padding: 20px;
  263. position: relative;
  264. background: #fff;
  265. .title-box {
  266. display: flex;
  267. align-items: center;
  268. margin-bottom: 12px;
  269. padding-right: 160px;
  270. position: relative;
  271. > img {
  272. width: 40px;
  273. margin-right: 16px;
  274. cursor: pointer;
  275. }
  276. }
  277. .title {
  278. font-size: 24px;
  279. margin-bottom: 20px;
  280. line-height: 40px;
  281. margin: 0;
  282. }
  283. .has-module {
  284. display: flex;
  285. justify-content: flex-start;
  286. align-items: flex-start;
  287. &-tree {
  288. width: 340px;
  289. height: 100%;
  290. overflow: auto;
  291. padding: 20px 0px;
  292. border-right: 1px solid #d9d9d9;
  293. }
  294. .inner {
  295. // border-left: 1px solid #d9d9d9;
  296. width: 1000px;
  297. flex: 1;
  298. margin: 0 auto;
  299. box-sizing: border-box;
  300. padding: 20px;
  301. position: relative;
  302. background: #fff;
  303. .title-box {
  304. display: flex;
  305. align-items: center;
  306. margin-bottom: 12px;
  307. padding-right: 160px;
  308. position: relative;
  309. > img {
  310. width: 40px;
  311. margin-right: 16px;
  312. cursor: pointer;
  313. }
  314. }
  315. .title {
  316. font-size: 24px;
  317. margin-bottom: 20px;
  318. line-height: 40px;
  319. margin: 0;
  320. }
  321. .has-module {
  322. display: flex;
  323. justify-content: flex-start;
  324. align-items: flex-start;
  325. }
  326. .edit-btn {
  327. display: inline-block;
  328. font-size: 14px;
  329. background: #ff9900;
  330. float: right;
  331. line-height: 36px;
  332. color: #fff;
  333. width: 60px;
  334. text-align: center;
  335. border-radius: 4px;
  336. }
  337. }
  338. }
  339. }
  340. .nav-list {
  341. width: 200px;
  342. height: 40px;
  343. background: rgba(49, 212, 134, 0.2);
  344. border-radius: 240px;
  345. display: flex;
  346. justify-content: flex-start;
  347. align-items: center;
  348. padding: 0;
  349. margin: 0;
  350. margin-bottom: 10px;
  351. list-style: none;
  352. > li {
  353. height: 40px;
  354. width: 100px;
  355. text-align: center;
  356. font-style: normal;
  357. font-weight: bold;
  358. font-size: 14px;
  359. line-height: 40px;
  360. color: #19b068;
  361. cursor: pointer;
  362. &.active {
  363. background: #19b068;
  364. border-radius: 240px;
  365. color: #ffffff;
  366. }
  367. }
  368. }
  369. }
  370. .screen-full {
  371. position: absolute;
  372. right: 30px;
  373. bottom: 30px;
  374. width: 48px;
  375. height: 48px;
  376. background: rgba(0, 0, 0, 0.4) url("../assets/common/icon-screenFull.png")
  377. center no-repeat;
  378. background-size: 32px;
  379. }
  380. .answerShow {
  381. position: absolute;
  382. right: 20px;
  383. top: 20px;
  384. width: 112px;
  385. height: 40px;
  386. background: #ffffff url("../assets/common/icon-eye-close.png") 16px center
  387. no-repeat;
  388. background-size: 16px;
  389. border: 1px solid rgba(44, 44, 44, 0.15);
  390. box-sizing: border-box;
  391. border-radius: 4px;
  392. font-size: 14px;
  393. line-height: 150%;
  394. color: #000000;
  395. padding: 9px 16px 9px 36px;
  396. cursor: pointer;
  397. z-index: 2;
  398. &.answerShowTrue {
  399. background: #f5f5f5 url("../assets/common/icon-eye-open.png") 16px center
  400. no-repeat;
  401. background-size: 16px;
  402. }
  403. }
  404. }
  405. </style>
  406. <style lang="scss">
  407. .title-box {
  408. .el-switch {
  409. position: absolute;
  410. top: 0;
  411. right: 0px;
  412. border: 1px solid rgba(44, 44, 44, 0.15);
  413. border-radius: 40px;
  414. height: 40px;
  415. padding: 6px 6px 6px 16px;
  416. }
  417. .el-switch__label.is-active {
  418. color: #000000;
  419. font-size: 16px;
  420. }
  421. }
  422. </style>