index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div class="home-box">
  3. <van-nav-bar v-if="env!=='pro'" title="京臻学堂" left-text right-text bind:click-left bind:click-right></van-nav-bar>
  4. <div v-show="activeTabName === 0" class="dropdown-div"></div>
  5. <transition name="tab" mode="out-in">
  6. <component :is="currentComponents" class="page" />
  7. </transition>
  8. <van-tabbar
  9. v-model="activeTabName"
  10. active-color="#0088e9"
  11. inactive-color="#808080"
  12. @change="onChangeTabFun"
  13. >
  14. <van-tabbar-item v-for="(item, index) in tabbars" :key="index">
  15. <span>{{ item.title }}</span>
  16. <template #icon="props">
  17. <img :src="props.active ? item.iconActive : item.iconInactive" />
  18. </template>
  19. </van-tabbar-item>
  20. </van-tabbar>
  21. </div>
  22. </template>
  23. <script>
  24. import PageLearn from "./learn/page-learn";
  25. import PageAnswer from "./answer/page-answer";
  26. import PageExam from "./exam/page-exam";
  27. import PagePerson from "./person/page-person";
  28. import { mapState } from "vuex";
  29. export default {
  30. name: "home",
  31. components: { PageLearn, PageAnswer, PageExam, PagePerson },
  32. data() {
  33. return {
  34. currentComponents: "pageLearn",
  35. activeTabName: 0,
  36. tabbars: [
  37. {
  38. title: "学习",
  39. pageName: "pageLearn",
  40. iconInactive: require("@/assets/image/homeTab/study.png"),
  41. iconActive: require("@/assets/image/homeTab/studyActive.png")
  42. },
  43. {
  44. title: "答题",
  45. pageName: "pageAnswer",
  46. iconInactive: require("@/assets/image/homeTab/answer.png"),
  47. iconActive: require("@/assets/image/homeTab/answerActive.png")
  48. },
  49. {
  50. title: "考试",
  51. pageName: "pageExam",
  52. iconInactive: require("@/assets/image/homeTab/exam.png"),
  53. iconActive: require("@/assets/image/homeTab/examActive.png")
  54. },
  55. {
  56. title: "我的",
  57. pageName: "pagePerson",
  58. iconInactive: require("@/assets/image/homeTab/person.png"),
  59. iconActive: require("@/assets/image/homeTab/personActive.png")
  60. }
  61. ],
  62. engineeringWorkChooseValue: null, // 工种选择的值
  63. engineeringWorkList: [], // 工种可选列表
  64. env: "pro"
  65. };
  66. },
  67. computed: {
  68. ...mapState({
  69. user: state => state.user,
  70. homeChangeTabIndex: state => state.study.homeChangeTabIndex
  71. })
  72. },
  73. created() {
  74. this.env = process.env.VUE_APP_ENV;
  75. console.log("---env---" + this.env);
  76. this.initFun();
  77. },
  78. activated() {
  79. this.setLanXinNavigator();
  80. },
  81. mounted() {},
  82. watch: {
  83. // 监听:首页切换tab的下标
  84. homeChangeTabIndex(value) {
  85. if (value === null || value === undefined) {
  86. return;
  87. }
  88. this.activeTabName = value;
  89. this.onChangeTabFun(this.activeTabName);
  90. this.$store.commit("updateStudyItemStore", {
  91. field: "homeChangeTabIndex",
  92. value: null
  93. });
  94. }
  95. },
  96. methods: {
  97. // 设置蓝信navigator
  98. setLanXinNavigator() {
  99. lx.ui.setNavigationBarTitle({
  100. title: "京臻学堂"
  101. });
  102. },
  103. // 初始化
  104. async initFun() {
  105. // 获取所有用户
  106. if (this.env === "pro") {
  107. // 从蓝信获取用户信息
  108. // this.getLanXinSignature();
  109. console.log("-从蓝信获取用户信息-");
  110. this.getLanXinCode();
  111. } else {
  112. console.log("-从本地获取用户信息-");
  113. await this.$_http
  114. .get(this.$_API.JTXT_GET_USER_ADMIN_USERS)
  115. .then(res => {
  116. this.$store.commit("updateUserItemStore", {
  117. field: "userInfo",
  118. value: res.data.content[0]
  119. });
  120. })
  121. .catch(() => {
  122. this.$store.commit("toggleLoading", false);
  123. });
  124. }
  125. // 获取所有收藏
  126. this.getCollection();
  127. // 获取所有考试历史
  128. this.getExamHistory();
  129. // 查询工作信息
  130. this.getEngineeringWorkList();
  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) {
  147. this.$store.commit("updateFavoriteItemStore", {
  148. field: "materials",
  149. value: res.data
  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.content.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. getEngineeringWorkList() {
  184. // this.engineeringWorkList = [
  185. // { text: "桥隧工", value: "QiaoSuiGong" },
  186. // // { text: "测量工", value: "CeLiangGong" },
  187. // { text: "线路工", value: "XianLuGong" }
  188. // ];
  189. this.$_http
  190. .get(this.$_API.JTXT_GET_ENGINEERINGWORK_LIST)
  191. .then(res => {
  192. // this.engineeringWorkList.push({ "id": "", "name": "全部" });
  193. this.engineeringWorkList = [...this.engineeringWorkList, ...res.data];
  194. this.engineeringWorkList.forEach(element => {
  195. element["text"] = element.name;
  196. element["value"] = element.name;
  197. });
  198. // 选择工作列表
  199. this.engineeringWorkChooseValue =
  200. this.chooseEngneeringWork && this.chooseEngneeringWork.value
  201. ? this.chooseEngneeringWork.value
  202. : this.engineeringWorkList[0].value;
  203. this.handleChangeEngneeringWorkFun(this.engineeringWorkChooseValue);
  204. })
  205. .catch(() => {
  206. this.$store.commit("toggleLoading", false);
  207. });
  208. },
  209. // 操作:选择了工种
  210. handleChangeEngneeringWorkFun(value) {
  211. let resultItem = null;
  212. for (let i = 0; i < this.engineeringWorkList.length; i++) {
  213. let item = this.engineeringWorkList[i];
  214. if (value === item.value) {
  215. resultItem = item;
  216. break;
  217. }
  218. }
  219. this.$store.commit("updateUserItemStore", {
  220. field: "chooseEngneeringWork",
  221. value: resultItem
  222. });
  223. },
  224. // 获取蓝信签名和鉴权
  225. getLanXinSignature() {
  226. this.$store.commit("toggleLoading", true);
  227. let params = {
  228. url: this.$route.fullPath
  229. };
  230. this.$_http
  231. .get(this.$_API.JTXT_GET_LAN_XIN_SIGNATURE, { params })
  232. .then(res => {
  233. console.log("蓝信签名---" + JSON.stringify(res));
  234. lx.config({
  235. appId: process.env.VUE_APP_LANXIN_APPID,
  236. timestamp: res.data.timestamp,
  237. nonceStr: res.data.noncestr,
  238. signature: res.data.signature
  239. });
  240. })
  241. .catch(() => {
  242. this.$store.commit("toggleLoading", false);
  243. });
  244. },
  245. // 获取蓝信免登陆授权吗
  246. getLanXinCode() {
  247. lx.biz
  248. .getAuthCode({
  249. appId: process.env.VUE_APP_LANXIN_APPID
  250. })
  251. .then(res => {
  252. console.log("getLanXinCode--code-" + JSON.stringify(res));
  253. let authCode = res.authCode;
  254. this.getLanXinUserInfo(authCode);
  255. });
  256. },
  257. // 获取蓝信用户信息
  258. getLanXinUserInfo(authCode) {
  259. let params = { authCode: authCode };
  260. this.$_http
  261. .get(this.$_API.JTXT_GET_LAN_XIN_USER_INFO, { params })
  262. .then(res => {
  263. this.$store.commit("updateUserItemStore", {
  264. field: "userInfo",
  265. value: res.data
  266. });
  267. console.log("蓝信用户信息---" + JSON.stringify(res));
  268. })
  269. .catch(() => {
  270. this.$store.commit("toggleLoading", false);
  271. });
  272. },
  273. // 蓝信API调用例子
  274. lanXinTest() {
  275. lx.biz.chooseContacts(
  276. {
  277. title: "选择人员", // 选择窗体标题
  278. multiple: true, // 是否允许多选
  279. type: ["friend", "staff", "sector"], // 选择人员窗体tab选项卡类型,friend 好友,staff 组织人员, sector 组织部门
  280. canChooseExternal: false, // 是否可以选择跨组织的外部人员
  281. max: 10, // 可选最大数量,当允许多选时生效,默认根据当前组织云控配置
  282. maxTip: "最多选择10人", // 选择数量超出最大限制提示
  283. existentStaffs: [], // 已选择的人员staffId列表
  284. existentSectors: [], // 已选择的部门sectorId列表
  285. requiredStaffs: [], // 默认选中的人员staffId列表,不可取消选中
  286. selectGroupMembers: false // 是否默认选中群成员,仅在群入口生效,默认false
  287. },
  288. success => {},
  289. fail => {}
  290. );
  291. }
  292. }
  293. };
  294. </script>
  295. <style lang="scss" scoped>
  296. .home-box {
  297. height: 100%; // 不要设置vh,手机浏览器计算问题
  298. padding-bottom: 2rem; // 多2em,避免tab栏挡住内容
  299. }
  300. </style>
  301. <style lang="scss"></style>