index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <template>
  2. <div class="home-box">
  3. <van-nav-bar
  4. title="京铁学堂"
  5. left-text=""
  6. right-text=""
  7. bind:click-left=""
  8. bind:click-right=""
  9. >
  10. </van-nav-bar>
  11. <div class="dropdown-div">
  12. <van-dropdown-menu active-color="#1989fa">
  13. <van-dropdown-item
  14. v-model="engineeringWorkChooseValue"
  15. :options="engineeringWorkList"
  16. :title="
  17. engineeringWorkChooseValue
  18. ? engineeringWorkChooseValue.text
  19. : '工种选择'
  20. "
  21. @change="handleChangeEngneeringWorkFun"
  22. />
  23. </van-dropdown-menu>
  24. </div>
  25. <transition name="tab" mode="out-in">
  26. <component :is="currentComponents" class="page" />
  27. </transition>
  28. <van-tabbar
  29. v-model="activeTabName"
  30. active-color="#0088e9"
  31. inactive-color="#808080"
  32. @change="onChangeTabFun"
  33. >
  34. <van-tabbar-item v-for="(item, index) in tabbars" :key="index">
  35. <span>{{ item.title }}</span>
  36. <template #icon="props">
  37. <img :src="props.active ? item.iconActive : item.iconInactive" />
  38. </template>
  39. </van-tabbar-item>
  40. </van-tabbar>
  41. </div>
  42. </template>
  43. <script>
  44. import PageLearn from "./learn/page-learn";
  45. import PageAnswer from "./answer/page-answer";
  46. import PageExam from "./exam/page-exam";
  47. import PagePerson from "./person/page-person";
  48. import { mapState } from "vuex";
  49. export default {
  50. name: "home",
  51. components: { PageLearn, PageAnswer, PageExam, PagePerson },
  52. data() {
  53. return {
  54. currentComponents: "pageLearn",
  55. activeTabName: 0,
  56. tabbars: [
  57. {
  58. title: "学习",
  59. pageName: "pageLearn",
  60. iconInactive: require("@/assets/image/homeTab/study.png"),
  61. iconActive: require("@/assets/image/homeTab/studyActive.png")
  62. },
  63. {
  64. title: "答题",
  65. pageName: "pageAnswer",
  66. iconInactive: require("@/assets/image/homeTab/answer.png"),
  67. iconActive: require("@/assets/image/homeTab/answerActive.png")
  68. },
  69. {
  70. title: "考试",
  71. pageName: "pageExam",
  72. iconInactive: require("@/assets/image/homeTab/exam.png"),
  73. iconActive: require("@/assets/image/homeTab/examActive.png")
  74. },
  75. {
  76. title: "我的",
  77. pageName: "pagePerson",
  78. iconInactive: require("@/assets/image/homeTab/person.png"),
  79. iconActive: require("@/assets/image/homeTab/personActive.png")
  80. }
  81. ],
  82. engineeringWorkChooseValue: null, // 工种选择的值
  83. engineeringWorkList: "" // 工种可选列表
  84. };
  85. },
  86. computed: {
  87. ...mapState({
  88. user: state => state.user,
  89. homeChangeTabIndex: state => state.study.homeChangeTabIndex
  90. })
  91. },
  92. created() {
  93. this.initFun();
  94. },
  95. watch: {
  96. // 监听:首页切换tab的下标
  97. homeChangeTabIndex(value) {
  98. if (value === null || value === undefined) {
  99. return;
  100. }
  101. this.activeTabName = value;
  102. this.onChangeTabFun(this.activeTabName);
  103. this.$store.commit("updateStudyItemStore", {
  104. field: "homeChangeTabIndex",
  105. value: null
  106. });
  107. }
  108. },
  109. methods: {
  110. // 初始化
  111. initFun() {
  112. this.engineeringWorkList = [
  113. { text: "桥隧工", value: "QiaoSuiGong" },
  114. { text: "桥梁工", value: "QiaoLiangGong" },
  115. { text: "线路工", value: "XianLuGong" }
  116. ];
  117. this.engineeringWorkChooseValue = this.engineeringWorkList[0].value;
  118. this.handleChangeEngneeringWorkFun(this.engineeringWorkChooseValue);
  119. // 获取所有用户
  120. this.$_http
  121. .get(this.$_API.JTXT_GET_USER_ADMIN_USERS)
  122. .then(res => {
  123. this.$store.commit("updateUserItemStore", {
  124. field: "userInfo",
  125. value: res.data[0]
  126. });
  127. // 获取所有收藏
  128. this.getCollection();
  129. // 获取所有考试历史
  130. this.getExamHistory();
  131. })
  132. .catch(() => {
  133. this.$store.commit("toggleLoading", false);
  134. });
  135. this.activeTabName = 0;
  136. this.onChangeTabFun(this.activeTabName);
  137. },
  138. // 操作:切换tab
  139. onChangeTabFun(index) {
  140. this.currentComponents = this.tabbars[this.activeTabName].pageName;
  141. },
  142. // 操作:选择了工种
  143. handleChangeEngneeringWorkFun(value) {
  144. let resultItem = null;
  145. for (let i = 0; i < this.engineeringWorkList.length; i++) {
  146. let item = this.engineeringWorkList[i];
  147. if (value === item.value) {
  148. resultItem = item;
  149. break;
  150. }
  151. }
  152. this.$store.commit("updateUserItemStore", {
  153. field: "chooseEngneeringWork",
  154. value: resultItem
  155. });
  156. },
  157. // 获取所有收藏
  158. getCollection() {
  159. let path = {
  160. userName: this.user.userInfo.userName
  161. };
  162. this.$_http
  163. .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))
  164. .then(res => {
  165. if (res.data.materials) {
  166. this.$store.commit("updateFavoriteItemStore", {
  167. field: "materials",
  168. value: res.data.materials
  169. });
  170. this.$store.commit("updateFavoriteItemStore", {
  171. field: "titles",
  172. value: res.data.titles
  173. });
  174. } else {
  175. this.$store.commit("toggleLoading", false);
  176. }
  177. this.loading = false;
  178. })
  179. .catch(() => {
  180. this.$store.commit("toggleLoading", false);
  181. });
  182. },
  183. // 查询:考试记录
  184. getExamHistory() {
  185. this.$store.commit("toggleLoading", true);
  186. let params = {
  187. user: this.user.userInfo.userName
  188. };
  189. this.$_http
  190. .get(this.$_API.JTXT_GET_USER_EXAMS_HISTORY, { params })
  191. .then(res => {
  192. let obj = {};
  193. res.data.forEach(element => {
  194. obj[element.examId] = element;
  195. });
  196. this.$store.commit("updateExamItemStore", {
  197. field: "examHistoryObj",
  198. value: obj
  199. });
  200. })
  201. .catch(() => {
  202. this.$store.commit("toggleLoading", false);
  203. });
  204. }
  205. }
  206. };
  207. </script>
  208. <style lang="scss" scoped>
  209. .home-box {
  210. height: 100%; // 不要设置vh,手机浏览器计算问题
  211. padding-bottom: 2rem; // 多2em,避免tab栏挡住内容
  212. .dropdown-div {
  213. position: absolute;
  214. top: 0;
  215. right: 0.5rem;
  216. width: 5rem;
  217. height: 2.09091rem;
  218. overflow: hidden;
  219. z-index: 1000;
  220. }
  221. }
  222. </style>
  223. <style lang="scss">
  224. .home-box {
  225. .van-dropdown-menu__bar {
  226. background-color: #7cc8ff;
  227. .van-ellipsis {
  228. font-size: 0.6rem;
  229. }
  230. }
  231. }
  232. </style>