index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 v-show="activeTabName === 0" class="dropdown-div">
  12. </div>
  13. <transition name="tab" mode="out-in">
  14. <component :is="currentComponents" class="page" />
  15. </transition>
  16. <van-tabbar
  17. v-model="activeTabName"
  18. active-color="#0088e9"
  19. inactive-color="#808080"
  20. @change="onChangeTabFun"
  21. >
  22. <van-tabbar-item v-for="(item, index) in tabbars" :key="index">
  23. <span>{{ item.title }}</span>
  24. <template #icon="props">
  25. <img :src="props.active ? item.iconActive : item.iconInactive" />
  26. </template>
  27. </van-tabbar-item>
  28. </van-tabbar>
  29. </div>
  30. </template>
  31. <script>
  32. import PageLearn from "./learn/page-learn";
  33. import PageAnswer from "./answer/page-answer";
  34. import PageExam from "./exam/page-exam";
  35. import PagePerson from "./person/page-person";
  36. import { mapState } from "vuex";
  37. export default {
  38. name: "home",
  39. components: { PageLearn, PageAnswer, PageExam, PagePerson },
  40. data() {
  41. return {
  42. currentComponents: "pageLearn",
  43. activeTabName: 0,
  44. tabbars: [
  45. {
  46. title: "学习",
  47. pageName: "pageLearn",
  48. iconInactive: require("@/assets/image/homeTab/study.png"),
  49. iconActive: require("@/assets/image/homeTab/studyActive.png")
  50. },
  51. {
  52. title: "答题",
  53. pageName: "pageAnswer",
  54. iconInactive: require("@/assets/image/homeTab/answer.png"),
  55. iconActive: require("@/assets/image/homeTab/answerActive.png")
  56. },
  57. {
  58. title: "考试",
  59. pageName: "pageExam",
  60. iconInactive: require("@/assets/image/homeTab/exam.png"),
  61. iconActive: require("@/assets/image/homeTab/examActive.png")
  62. },
  63. {
  64. title: "我的",
  65. pageName: "pagePerson",
  66. iconInactive: require("@/assets/image/homeTab/person.png"),
  67. iconActive: require("@/assets/image/homeTab/personActive.png")
  68. }
  69. ]
  70. };
  71. },
  72. computed: {
  73. ...mapState({
  74. user: state => state.user,
  75. homeChangeTabIndex: state => state.study.homeChangeTabIndex
  76. })
  77. },
  78. created() {
  79. this.initFun();
  80. // this.getLanXinSignature();
  81. this.getLanXinCode();
  82. },
  83. activated() {
  84. this.setLanXinNavigator();
  85. },
  86. mounted() {
  87. },
  88. watch: {
  89. // 监听:首页切换tab的下标
  90. homeChangeTabIndex(value) {
  91. if (value === null || value === undefined) {
  92. return;
  93. }
  94. this.activeTabName = value;
  95. this.onChangeTabFun(this.activeTabName);
  96. this.$store.commit("updateStudyItemStore", {
  97. field: "homeChangeTabIndex",
  98. value: null
  99. });
  100. }
  101. },
  102. methods: {
  103. // 设置蓝信navigator
  104. setLanXinNavigator() {
  105. lx.ui.setNavigationBarTitle({
  106. title: "京铁学堂"
  107. });
  108. },
  109. // 初始化
  110. initFun() {
  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.content[0]
  118. });
  119. // 获取所有收藏
  120. this.getCollection();
  121. // 获取所有考试历史
  122. this.getExamHistory();
  123. })
  124. .catch(() => {
  125. this.$store.commit("toggleLoading", false);
  126. });
  127. this.activeTabName = 0;
  128. this.onChangeTabFun(this.activeTabName);
  129. },
  130. // 操作:切换tab
  131. onChangeTabFun(index) {
  132. this.currentComponents = this.tabbars[this.activeTabName].pageName;
  133. },
  134. // 获取所有收藏
  135. getCollection() {
  136. let path = {
  137. userName: this.user.userInfo.userName
  138. };
  139. this.$_http
  140. .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))
  141. .then(res => {
  142. if (res.data.materials) {
  143. this.$store.commit("updateFavoriteItemStore", {
  144. field: "materials",
  145. value: res.data.materials
  146. });
  147. this.$store.commit("updateFavoriteItemStore", {
  148. field: "titles",
  149. value: res.data.titles
  150. });
  151. } else {
  152. this.$store.commit("toggleLoading", false);
  153. }
  154. this.loading = false;
  155. })
  156. .catch(() => {
  157. this.$store.commit("toggleLoading", false);
  158. });
  159. },
  160. // 查询:考试记录
  161. getExamHistory() {
  162. this.$store.commit("toggleLoading", true);
  163. let params = {
  164. user: this.user.userInfo.userName
  165. };
  166. this.$_http
  167. .get(this.$_API.JTXT_GET_USER_EXAMS_HISTORY, { params })
  168. .then(res => {
  169. let obj = {};
  170. res.data.forEach(element => {
  171. obj[element.examId] = element;
  172. });
  173. this.$store.commit("updateExamItemStore", {
  174. field: "examHistoryObj",
  175. value: obj
  176. });
  177. })
  178. .catch(() => {
  179. this.$store.commit("toggleLoading", false);
  180. });
  181. },
  182. // 获取蓝信签名和鉴权
  183. getLanXinSignature() {
  184. this.$store.commit("toggleLoading", true);
  185. let params = {
  186. url: this.$route.fullPath
  187. };
  188. this.$_http
  189. .get(this.$_API.JTXT_GET_LAN_XIN_SIGNATURE, { params })
  190. .then(res => {
  191. console.log("蓝信签名---" + JSON.stringify(res));
  192. lx.config({
  193. appId: process.env.VUE_APP_LANXIN_APPID,
  194. timestamp: res.data.timestamp,
  195. nonceStr: res.data.noncestr,
  196. signature: res.data.signature
  197. });
  198. })
  199. .catch(() => {
  200. this.$store.commit("toggleLoading", false);
  201. });
  202. },
  203. // 获取蓝信免登陆授权吗
  204. getLanXinCode() {
  205. console.log("getLanXinCode--code-");
  206. lx.biz
  207. .getAuthCode({
  208. appId: process.env.VUE_APP_LANXIN_APPID
  209. })
  210. .then(res => {
  211. let authCode = res.authCode;
  212. this.getLanXinUserInfo(authCode);
  213. });
  214. },
  215. // 获取蓝信用户信息
  216. getLanXinUserInfo(authCode) {
  217. let params = { authCode: authCode };
  218. this.$_http
  219. .get(this.$_API.JTXT_GET_LAN_XIN_USER_INFO, { params })
  220. .then(res => {
  221. console.log("蓝信用户信息---" + JSON.stringify(res));
  222. })
  223. .catch(() => {
  224. this.$store.commit("toggleLoading", false);
  225. });
  226. },
  227. // 蓝信API调用例子
  228. lanXinTest() {
  229. lx.biz.chooseContacts(
  230. {
  231. title: "选择人员", // 选择窗体标题
  232. multiple: true, // 是否允许多选
  233. type: ["friend", "staff", "sector"], // 选择人员窗体tab选项卡类型,friend 好友,staff 组织人员, sector 组织部门
  234. canChooseExternal: false, // 是否可以选择跨组织的外部人员
  235. max: 10, // 可选最大数量,当允许多选时生效,默认根据当前组织云控配置
  236. maxTip: "最多选择10人", // 选择数量超出最大限制提示
  237. existentStaffs: [], // 已选择的人员staffId列表
  238. existentSectors: [], // 已选择的部门sectorId列表
  239. requiredStaffs: [], // 默认选中的人员staffId列表,不可取消选中
  240. selectGroupMembers: false // 是否默认选中群成员,仅在群入口生效,默认false
  241. },
  242. success => {},
  243. fail => {}
  244. );
  245. }
  246. }
  247. };
  248. </script>
  249. <style lang="scss" scoped>
  250. .home-box {
  251. height: 100%; // 不要设置vh,手机浏览器计算问题
  252. padding-bottom: 2rem; // 多2em,避免tab栏挡住内容
  253. }
  254. </style>
  255. <style lang="scss">
  256. </style>