myCenter.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. // pages/nais/nais.js
  2. import {
  3. imgUrl
  4. } from "../api/request"
  5. import {
  6. cacheGet
  7. } from "../../utils/cacheUtil"
  8. import {
  9. baseUrl,
  10. request
  11. } from "../../pages/api/canteen-request.js"
  12. let app = getApp();
  13. Page({
  14. /**
  15. * 页面的初始数据
  16. */
  17. data: {
  18. canIUseGetUserProfile: true,
  19. nickName: "",
  20. avatarUrl: "",
  21. hasUserInfo: false,
  22. imgUrl: imgUrl,
  23. show: false,
  24. showWorkOrder: false
  25. },
  26. // 自定义函数
  27. toCanteen: function (e) {
  28. wx.navigateTo({
  29. url: '/pages/ourCanteen/ourCanteen'
  30. })
  31. },
  32. toWorkOrder: function (e) {
  33. wx.navigateTo({
  34. url: '/pagesPublic/pages/work-order/work-order'
  35. });
  36. },
  37. handleAction() {
  38. var that = this
  39. wx.showActionSheet({
  40. itemList: ['退出登录'],
  41. success(res) {
  42. console.log(res.tapIndex)
  43. wx.clearStorageSync();
  44. that.setData({
  45. show: false,
  46. canIUseGetUserProfile: true,
  47. hasUserInfo: false
  48. })
  49. },
  50. fail(res) {
  51. console.log(res.errMsg)
  52. }
  53. })
  54. },
  55. /**
  56. * 生命周期函数--监听页面初次渲染完成
  57. */
  58. onReady() {
  59. if (typeof this.getTabBar === 'function' &&
  60. this.getTabBar()) {
  61. this.getTabBar().setData({
  62. selected: 4
  63. })
  64. }
  65. },
  66. /**
  67. * 生命周期函数--监听页面显示
  68. */
  69. onShow() {
  70. // let token = wx.getStorageSync('token');
  71. let token = cacheGet('token');
  72. if (token != null && token != '') {
  73. this.setData({
  74. canIUseGetUserProfile: false,
  75. nickName: wx.getStorageSync('nickName'),
  76. avatarUrl: wx.getStorageSync('imgUrl'),
  77. hasUserInfo: true
  78. })
  79. } else {
  80. this.setData({
  81. hasUserInfo: false,
  82. canIUseGetUserProfile: true
  83. })
  84. }
  85. if (typeof this.getTabBar === 'function' &&
  86. this.getTabBar()) {
  87. this.getTabBar().setData({
  88. selected: 4
  89. })
  90. }
  91. },
  92. onHide() {
  93. if (typeof this.getTabBar === 'function' &&
  94. this.getTabBar()) {
  95. this.getTabBar().setData({
  96. selected: -1
  97. })
  98. }
  99. },
  100. onLoad() {
  101. // let token = wx.getStorageSync('token');
  102. let token = cacheGet('token');
  103. if (token != null && token != '') {
  104. this.setData({
  105. nickName: wx.getStorageSync('nickName'),
  106. avatarUrl: wx.getStorageSync('imgUrl'),
  107. hasUserInfo: true
  108. })
  109. }
  110. // 获取用户角色
  111. request({
  112. url: '/mini/worker/getUserType',
  113. method: 'GET',
  114. data: {
  115. userId: wx.getStorageSync('userid')
  116. }
  117. }).then(res => {
  118. if (res.result) {
  119. let userType = res.data;
  120. if ("0" == userType || "2" == userType) {
  121. // 显示工单维修菜单
  122. this.setData({
  123. showWorkOrder: true
  124. });
  125. }
  126. }
  127. });
  128. },
  129. /**
  130. * 生命周期函数--监听页面卸载
  131. */
  132. onUnload() {
  133. },
  134. /**
  135. * 页面相关事件处理函数--监听用户下拉动作
  136. */
  137. onPullDownRefresh() {
  138. },
  139. /**
  140. * 页面上拉触底事件的处理函数
  141. */
  142. onReachBottom() {
  143. },
  144. /**
  145. * 用户点击右上角分享
  146. */
  147. onShareAppMessage() {
  148. return {
  149. title: '个人中心'
  150. }
  151. },
  152. toLike() {
  153. wx.navigateTo({
  154. url: '/pagesPublic/pages/like/like',
  155. })
  156. },
  157. navto() {
  158. wx.navigateTo({
  159. url: '/pagesPublic/pages/menu/menu',
  160. })
  161. },
  162. // toPersonalData() {
  163. // wx.navigateTo({
  164. // url: '/pagesPublic/pages/personalData/index/personalData',
  165. // })
  166. // },
  167. gotoMyCollection() {
  168. wx.navigateTo({
  169. url: '/pagesPublic/pages/myCollection/myCollection',
  170. })
  171. },
  172. toMyComment() {
  173. wx.navigateTo({
  174. url: '/pagesPublic/pages/myComment/myComment',
  175. })
  176. },
  177. tologin() {
  178. wx.navigateTo({
  179. url: '/pages/login/login',
  180. })
  181. },
  182. getUserInfo() {
  183. // this.setData({
  184. // nickName: wx.getStorageSync('nickName'),
  185. // avatarUrl: wx.getStorageSync('imgUrl'),
  186. // hasUserInfo: true
  187. // })
  188. },
  189. // logout(){
  190. // this.setData({
  191. // hasUserInfo: false,
  192. // nickName:"",
  193. // avatarUrl:""
  194. // })
  195. // wx.removeStorage({
  196. // key: 'nickName',
  197. // })(option)
  198. // wx.removeStorage({
  199. // key: 'imgUrl',
  200. // })(option)
  201. // }
  202. })