Tabbar.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <template>
  2. <div>
  3. <van-tabbar v-model="active" placeholder route :before-change="beforeChange" active-color="#f0896e">
  4. <van-tabbar-item v-for="(item,index) in list" :key="index" :to="item.router">
  5. <span>{{item.text}}</span>
  6. <template #icon="props">
  7. <img :src="props.active ? item.selectedIconPath : item.iconPath" />
  8. </template>
  9. </van-tabbar-item>
  10. </van-tabbar>
  11. </div>
  12. </template>
  13. <script>
  14. import { userApi } from '../api/index.js'
  15. export default {
  16. data() {
  17. return {
  18. active: 0,
  19. list: [
  20. {
  21. iconPath: require('../assets/images/nav/home-off.png'),
  22. selectedIconPath: require('../assets/images/nav/home-on.png'),
  23. text: '首页',
  24. router: '/',
  25. },
  26. {
  27. iconPath: require('../assets/images/nav/book-off.png'),
  28. selectedIconPath: require('../assets/images/nav/book-on.png'),
  29. router: '/classRoom',
  30. text: '老年课堂',
  31. },
  32. {
  33. iconPath: require('../assets/images/nav/map-off.png'),
  34. selectedIconPath: require('../assets/images/nav/map-on.png'),
  35. router: '/circleHome',
  36. text: '养老服务圈',
  37. },
  38. // {
  39. // iconPath: require('../assets/images/nav/serve-store-off.png'),
  40. // selectedIconPath: require('../assets/images/nav/serve-store-on.png'),
  41. // router: '/shoppingMall',
  42. // text: '养老商城',
  43. // },
  44. // {
  45. // iconPath: require('../assets/images/nav/my-off.png'),
  46. // selectedIconPath: require('../assets/images/nav/my-on.png'),
  47. // text: '我的',
  48. // },
  49. {
  50. iconPath: require('../assets/images/nav/hea.png'),
  51. selectedIconPath: require('../assets/images/nav/hea1.png'),
  52. router: '/healthAssessmen',
  53. text: '健康管理',
  54. },
  55. ],
  56. appmark: 'sdzwapp',
  57. }
  58. },
  59. created() {},
  60. methods: {
  61. beforeChange(e) {
  62. if (e == 3) {
  63. if (!sessionStorage.getItem('userInfo')) {
  64. this.getUserInfo()
  65. } else {
  66. return true
  67. }
  68. } else {
  69. return true
  70. }
  71. },
  72. async userApi() {
  73. var userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
  74. // var mobile = '13895651855'
  75. const res = await userApi({
  76. command: 'reguserbyweixinphone',
  77. contactsPhone: userInfo.mobile,
  78. // contactsPhone: mobile,
  79. terminalType: 5,
  80. })
  81. sessionStorage.setItem('healthUser', JSON.stringify(res))
  82. // this.$toast(userInfo.name + '接口')
  83. // this.$dialog
  84. // .alert({
  85. // message: res.uname + '--------' + userInfo.name,
  86. // })
  87. // .then(() => {})
  88. this.$router.push({ path: '/healthAssessmen' })
  89. },
  90. /**
  91. * 通过jssdk方法获取APP本地用户票据
  92. */
  93. getUserInfo() {
  94. var that = this
  95. lightAppJssdk.user.getTicket({
  96. success: function (data) {
  97. //成功回调
  98. console.log(JSON.stringify(data), '111')
  99. if (data == '未登录') {
  100. onLoginApp() //APP用户未登录,调用登录页面
  101. } else {
  102. var jsonData = JSON.parse(data)
  103. if (jsonData.retcode == '000000') {
  104. var dataValueObj = JSON.parse(jsonData.data)
  105. var ticket = dataValueObj.ticket //解析出用户票据信息
  106. userType = dataValueObj.usertype //解析保存用户类型(个人法人)
  107. that.getUserToken(ticket)
  108. }
  109. }
  110. },
  111. fail: function (data) {
  112. //错误返回
  113. console.log(JSON.stringify(data))
  114. },
  115. })
  116. },
  117. /**
  118. * 使用jssdk调用登录页面
  119. */
  120. onLoginApp() {
  121. var that = this
  122. lightAppJssdk.user.loginapp({
  123. success: function (data) {
  124. if (data == '未登录') {
  125. //取消登录或登录失败,关闭页面
  126. oncloseWindow()
  127. } else {
  128. var dataObj = JSON.parse(data)
  129. if (dataObj.retcode == '000000') {
  130. //登录成功,返回用户的票据和用户类型
  131. var dataValueObj = JSON.parse(dataObj.data)
  132. that.getUserToken(dataValueObj.ticket) //解析出用户票据信息
  133. userType = jsonData.usertype //解析保存用户类型(个人法人)
  134. } else {
  135. //关闭页面
  136. oncloseWindow()
  137. }
  138. }
  139. },
  140. fail: function (data) {
  141. //关闭页面
  142. oncloseWindow()
  143. },
  144. })
  145. },
  146. /**
  147. * 通过用户票据获取用户的令牌数据,票据使用一次后失效,token时效性较长
  148. */
  149. getUserToken(ticket) {
  150. var that = this
  151. var params = '{"ticket":"' + ticket + '"}'
  152. const interfaceContent = {
  153. app_id: that.appmark,
  154. servicename: 'ticketValidate',
  155. params: params,
  156. }
  157. vaildInterfacefn(
  158. 'jisnzjk',
  159. 'ticketvalidate',
  160. JSON.stringify(interfaceContent),
  161. '2',
  162. 'https://' + urlCreatesign,
  163. 'https://' + urlGateway
  164. ).then((value) => {
  165. const data = JSON.parse(value)
  166. if (data.retcode == '000000') {
  167. const userToken = JSON.parse(data.data).token
  168. if (userType == '1') {
  169. //个人类型获取用户信息
  170. that.getUserInfoByToken(userToken)
  171. } else {
  172. //法人类型获取用户信息
  173. that.findCorUserByToken(userToken)
  174. }
  175. } else {
  176. lightAppJssdk.notification.alert({
  177. title: '提示', //可传空
  178. message: data.msg,
  179. buttonName: '确认',
  180. success: function (data) {
  181. oncloseWindow()
  182. },
  183. })
  184. }
  185. })
  186. },
  187. /**
  188. * 根据令牌获取个人完整信息
  189. */
  190. getUserInfoByToken(userToken) {
  191. var that = this
  192. const params = '{"token":"' + userToken + '"}'
  193. const interfaceContent = {
  194. app_id: that.appmark,
  195. servicename: 'findOutsideUserByToken',
  196. params: params,
  197. }
  198. try {
  199. vaildInterfacefn(
  200. 'jisnzjk',
  201. 'findoutsideuserbytoken',
  202. JSON.stringify(interfaceContent),
  203. '2',
  204. 'https://' + urlCreatesign,
  205. 'https://' + urlGateway
  206. ).then((value) => {
  207. const data = JSON.parse(value)
  208. if (data.retcode == '000000') {
  209. const userInfo = data.data
  210. sessionStorage.setItem('userInfo', userInfo)
  211. // that.$toast('调用接口getUserInfoByToken')
  212. that.userApi()
  213. } else {
  214. }
  215. })
  216. } catch (error) {}
  217. },
  218. /**
  219. * 根据令牌获取完整法人信息
  220. */
  221. findCorUserByToken(userToken) {
  222. var that = this
  223. try {
  224. const params = '{"token":"' + userToken + '"}'
  225. const interfaceContent = {
  226. app_id: that.appmark,
  227. servicename: 'findCorUserByToken',
  228. params: params,
  229. }
  230. vaildInterfacefn(
  231. 'jisnzjk',
  232. 'findcoruserytoken',
  233. JSON.stringify(interfaceContent),
  234. '2',
  235. 'https://' + urlCreatesign,
  236. 'https://' + urlGateway
  237. ).then((value) => {
  238. const data = JSON.parse(value)
  239. if (data.retcode == '000000') {
  240. const userInfo = JSON.stringify(data.data)
  241. // const userObj = JSON.parse(userInfo)
  242. sessionStorage.setItem('userInfo', userInfo)
  243. // document.getElementById('userinfo').innerText = userInfo
  244. // that.$toast('调用接口findCorUserByToken')
  245. that.userApi()
  246. } else {
  247. }
  248. })
  249. } catch (err) {}
  250. },
  251. /**
  252. * 关闭容器
  253. */
  254. oncloseWindow() {
  255. lightAppJssdk.navigation.close({
  256. success: function (data) {},
  257. fail: function (data) {},
  258. })
  259. },
  260. },
  261. }
  262. </script>