index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. props: {
  53. // 分组的数据列表
  54. propPcomponents: {
  55. type: String,
  56. default: "pageLearn"
  57. }
  58. },
  59. data() {
  60. return {
  61. currentComponents: "pageLearn",
  62. activeTabName: 0,
  63. tabbars: [
  64. {
  65. title: "学习",
  66. pageName: "pageLearn",
  67. iconInactive: require("@/assets/image/homeTab/study.png"),
  68. iconActive: require("@/assets/image/homeTab/studyActive.png")
  69. },
  70. {
  71. title: "答题",
  72. pageName: "pageAnswer",
  73. iconInactive: require("@/assets/image/homeTab/answer.png"),
  74. iconActive: require("@/assets/image/homeTab/answerActive.png")
  75. },
  76. {
  77. title: "考试",
  78. pageName: "pageExam",
  79. iconInactive: require("@/assets/image/homeTab/exam.png"),
  80. iconActive: require("@/assets/image/homeTab/examActive.png")
  81. },
  82. {
  83. title: "我的",
  84. pageName: "pagePerson",
  85. iconInactive: require("@/assets/image/homeTab/person.png"),
  86. iconActive: require("@/assets/image/homeTab/personActive.png")
  87. }
  88. ],
  89. engineeringWorkChooseValue: null, // 工种选择的值
  90. engineeringWorkList: "" // 工种可选列表
  91. };
  92. },
  93. computed: {
  94. ...mapState({
  95. user: state => state.user
  96. })
  97. },
  98. created() {
  99. this.initFun();
  100. },
  101. methods: {
  102. // 初始化
  103. initFun() {
  104. this.engineeringWorkList = [
  105. { text: "桥隧工", value: "QiaoSuiGong" },
  106. { text: "桥梁工", value: "QiaoLiangGong" },
  107. { text: "线路工", value: "XianLuGong" }
  108. ];
  109. this.engineeringWorkChooseValue = this.engineeringWorkList[0].value;
  110. this.handleChangeEngneeringWorkFun(this.engineeringWorkChooseValue);
  111. // 获取所有用户
  112. this.$_http
  113. .get(this.$_API.JTXT_GET_USER_ADMIN_USERS)
  114. .then(res => {
  115. this.$store.commit("updateUserItemStore", {
  116. field: "userInfo",
  117. value: res.data[0]
  118. });
  119. // 获取所有收藏
  120. this.getCollection();
  121. })
  122. .catch(() => {
  123. this.$store.commit("toggleLoading", false);
  124. });
  125. this.activeTabName = 0;
  126. this.onChangeTabFun(this.activeTabName);
  127. },
  128. // 操作:切换tab
  129. onChangeTabFun(index) {
  130. this.currentComponents = this.tabbars[this.activeTabName].pageName;
  131. },
  132. // 操作:选择了工种
  133. handleChangeEngneeringWorkFun(value) {
  134. let resultItem = null;
  135. for (let i = 0; i < this.engineeringWorkList.length; i++) {
  136. let item = this.engineeringWorkList[i];
  137. if (value === item.value) {
  138. resultItem = item;
  139. break;
  140. }
  141. }
  142. this.$store.commit("updateUserItemStore", {
  143. field: "chooseEngneeringWork",
  144. value: resultItem
  145. });
  146. },
  147. // 获取所有收藏
  148. getCollection() {
  149. let path = {
  150. userName: this.user.userInfo.userName
  151. };
  152. this.$_http
  153. .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))
  154. .then(res => {
  155. if (res.data.materials) {
  156. this.$store.commit("updateFavoriteItemStore", {
  157. field: "materials",
  158. value: res.data.materials
  159. });
  160. this.$store.commit("updateFavoriteItemStore", {
  161. field: "titles",
  162. value: res.data.titles
  163. });
  164. } else {
  165. this.$store.commit("toggleLoading", false);
  166. }
  167. this.loading = false;
  168. })
  169. .catch(() => {
  170. this.$store.commit("toggleLoading", false);
  171. });
  172. }
  173. }
  174. };
  175. </script>
  176. <style lang="scss" scoped>
  177. .home-box {
  178. height: 100%; // 不要设置vh,手机浏览器计算问题
  179. padding-bottom: 2rem; // 多2em,避免tab栏挡住内容
  180. .dropdown-div {
  181. position: absolute;
  182. top: 0;
  183. right: 0.5rem;
  184. width: 5rem;
  185. height: 2.09091rem;
  186. overflow: hidden;
  187. z-index: 1000;
  188. }
  189. }
  190. </style>
  191. <style lang="scss">
  192. .home-box {
  193. .van-dropdown-menu__bar {
  194. background-color: #7cc8ff;
  195. .van-ellipsis {
  196. font-size: 0.6rem;
  197. }
  198. }
  199. }
  200. </style>