index.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. engineeringWorkChooseValue: null, // 工种选择的值
  71. engineeringWorkList: [] // 工种可选列表
  72. };
  73. },
  74. computed: {
  75. ...mapState({
  76. user: state => state.user,
  77. homeChangeTabIndex: state => state.study.homeChangeTabIndex
  78. })
  79. },
  80. created() {
  81. this.initFun();
  82. // this.getLanXinSignature();
  83. this.getLanXinCode();
  84. },
  85. activated() {
  86. this.setLanXinNavigator();
  87. },
  88. mounted() {
  89. },
  90. watch: {
  91. // 监听:首页切换tab的下标
  92. homeChangeTabIndex(value) {
  93. if (value === null || value === undefined) {
  94. return;
  95. }
  96. this.activeTabName = value;
  97. this.onChangeTabFun(this.activeTabName);
  98. this.$store.commit("updateStudyItemStore", {
  99. field: "homeChangeTabIndex",
  100. value: null
  101. });
  102. }
  103. },
  104. methods: {
  105. // 设置蓝信navigator
  106. setLanXinNavigator() {
  107. lx.ui.setNavigationBarTitle({
  108. title: "京铁学堂"
  109. });
  110. },
  111. // 初始化
  112. initFun() {
  113. // 获取所有用户
  114. this.$_http
  115. .get(this.$_API.JTXT_GET_USER_ADMIN_USERS)
  116. .then(res => {
  117. this.$store.commit("updateUserItemStore", {
  118. field: "userInfo",
  119. value: res.data.content[0]
  120. });
  121. // 获取所有收藏
  122. this.getCollection();
  123. // 获取所有考试历史
  124. this.getExamHistory();
  125. // 查询工作信息
  126. this.getEngineeringWorkList();
  127. })
  128. .catch(() => {
  129. this.$store.commit("toggleLoading", false);
  130. });
  131. this.activeTabName = 0;
  132. this.onChangeTabFun(this.activeTabName);
  133. },
  134. // 操作:切换tab
  135. onChangeTabFun(index) {
  136. this.currentComponents = this.tabbars[this.activeTabName].pageName;
  137. },
  138. // 获取所有收藏
  139. getCollection() {
  140. let path = {
  141. userName: this.user.userInfo.userName
  142. };
  143. this.$_http
  144. .get(this.$pathParams(this.$_API.JTXT_GET_USER_FAVORITES, path))
  145. .then(res => {
  146. if (res.data.materials) {
  147. this.$store.commit("updateFavoriteItemStore", {
  148. field: "materials",
  149. value: res.data.materials
  150. });
  151. this.$store.commit("updateFavoriteItemStore", {
  152. field: "titles",
  153. value: res.data.titles
  154. });
  155. } else {
  156. this.$store.commit("toggleLoading", false);
  157. }
  158. this.loading = false;
  159. })
  160. .catch(() => {
  161. this.$store.commit("toggleLoading", false);
  162. });
  163. },
  164. // 查询:考试记录
  165. getExamHistory() {
  166. this.$store.commit("toggleLoading", true);
  167. let params = {
  168. user: this.user.userInfo.userName
  169. };
  170. this.$_http
  171. .get(this.$_API.JTXT_GET_USER_EXAMS_HISTORY, { params })
  172. .then(res => {
  173. let obj = {};
  174. res.data.forEach(element => {
  175. obj[element.examId] = element;
  176. });
  177. this.$store.commit("updateExamItemStore", {
  178. field: "examHistoryObj",
  179. value: obj
  180. });
  181. })
  182. .catch(() => {
  183. this.$store.commit("toggleLoading", false);
  184. });
  185. },
  186. // 初始化工种信息
  187. getEngineeringWorkList() {
  188. // this.engineeringWorkList = [
  189. // { text: "桥隧工", value: "QiaoSuiGong" },
  190. // // { text: "测量工", value: "CeLiangGong" },
  191. // { text: "线路工", value: "XianLuGong" }
  192. // ];
  193. this.$_http
  194. .get(this.$_API.JTXT_GET_ENGINEERINGWORK_LIST)
  195. .then(res => {
  196. this.engineeringWorkList = res.data;
  197. this.engineeringWorkList.forEach(element => {
  198. element["text"] = element.name;
  199. element["value"] = element.name;
  200. });
  201. // 选择工作列表
  202. this.engineeringWorkChooseValue =
  203. this.chooseEngneeringWork && this.chooseEngneeringWork.value
  204. ? this.chooseEngneeringWork.value
  205. : this.engineeringWorkList[0].value;
  206. this.handleChangeEngneeringWorkFun(this.engineeringWorkChooseValue);
  207. })
  208. .catch(() => {
  209. this.$store.commit("toggleLoading", false);
  210. });
  211. },
  212. // 操作:选择了工种
  213. handleChangeEngneeringWorkFun(value) {
  214. let resultItem = null;
  215. for (let i = 0; i < this.engineeringWorkList.length; i++) {
  216. let item = this.engineeringWorkList[i];
  217. if (value === item.value) {
  218. resultItem = item;
  219. break;
  220. }
  221. }
  222. this.$store.commit("updateUserItemStore", {
  223. field: "chooseEngneeringWork",
  224. value: resultItem
  225. });
  226. },
  227. // 获取蓝信签名和鉴权
  228. getLanXinSignature() {
  229. this.$store.commit("toggleLoading", true);
  230. let params = {
  231. url: this.$route.fullPath
  232. };
  233. this.$_http
  234. .get(this.$_API.JTXT_GET_LAN_XIN_SIGNATURE, { params })
  235. .then(res => {
  236. console.log("蓝信签名---" + JSON.stringify(res));
  237. lx.config({
  238. appId: process.env.VUE_APP_LANXIN_APPID,
  239. timestamp: res.data.timestamp,
  240. nonceStr: res.data.noncestr,
  241. signature: res.data.signature
  242. });
  243. })
  244. .catch(() => {
  245. this.$store.commit("toggleLoading", false);
  246. });
  247. },
  248. // 获取蓝信免登陆授权吗
  249. getLanXinCode() {
  250. console.log("getLanXinCode--code-");
  251. lx.biz
  252. .getAuthCode({
  253. appId: process.env.VUE_APP_LANXIN_APPID
  254. })
  255. .then(res => {
  256. let authCode = res.authCode;
  257. this.getLanXinUserInfo(authCode);
  258. });
  259. },
  260. // 获取蓝信用户信息
  261. getLanXinUserInfo(authCode) {
  262. let params = { authCode: authCode };
  263. this.$_http
  264. .get(this.$_API.JTXT_GET_LAN_XIN_USER_INFO, { params })
  265. .then(res => {
  266. console.log("蓝信用户信息---" + JSON.stringify(res));
  267. })
  268. .catch(() => {
  269. this.$store.commit("toggleLoading", false);
  270. });
  271. },
  272. // 蓝信API调用例子
  273. lanXinTest() {
  274. lx.biz.chooseContacts(
  275. {
  276. title: "选择人员", // 选择窗体标题
  277. multiple: true, // 是否允许多选
  278. type: ["friend", "staff", "sector"], // 选择人员窗体tab选项卡类型,friend 好友,staff 组织人员, sector 组织部门
  279. canChooseExternal: false, // 是否可以选择跨组织的外部人员
  280. max: 10, // 可选最大数量,当允许多选时生效,默认根据当前组织云控配置
  281. maxTip: "最多选择10人", // 选择数量超出最大限制提示
  282. existentStaffs: [], // 已选择的人员staffId列表
  283. existentSectors: [], // 已选择的部门sectorId列表
  284. requiredStaffs: [], // 默认选中的人员staffId列表,不可取消选中
  285. selectGroupMembers: false // 是否默认选中群成员,仅在群入口生效,默认false
  286. },
  287. success => {},
  288. fail => {}
  289. );
  290. }
  291. }
  292. };
  293. </script>
  294. <style lang="scss" scoped>
  295. .home-box {
  296. height: 100%; // 不要设置vh,手机浏览器计算问题
  297. padding-bottom: 2rem; // 多2em,避免tab栏挡住内容
  298. }
  299. </style>
  300. <style lang="scss">
  301. </style>