setting.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <view>
  3. <view class="d-flex j-between px3 py2 border-bottom" @tap="updateInfo">
  4. <view class="f-size-30 text-color-3">姓名</view>
  5. <view class="d-flex a-center">
  6. <view class="f-size-26">{{ userInfo.realName }}</view>
  7. <view class="ml-2 text-color-9">
  8. <view class="ml-2 text-color-9"> <u-icon name="arrow-right"></u-icon> </view>
  9. </view>
  10. </view>
  11. </view>
  12. <view class="d-flex j-between px3 py2 border-bottom a-center" @tap="updateInfo()">
  13. <view class="f-size-30 text-color-3">头像</view>
  14. <view class="d-flex a-center">
  15. <view class="f-size-26">
  16. <image
  17. :src="myAvatar"
  18. @error="myDefaultAvatar"
  19. mode=""
  20. style="width: 60rpx; height: 60rpx; border-radius: 50%"
  21. ></image>
  22. </view>
  23. <view class="ml-2 text-color-9">
  24. <view class="ml-2 text-color-9"> <u-icon name="arrow-right"></u-icon> </view>
  25. </view>
  26. </view>
  27. </view>
  28. <view class="d-flex j-between px3 py2 border-bottom" @tap="updateInfo">
  29. <view class="f-size-30 text-color-3">部门</view>
  30. <view class="d-flex a-center">
  31. <view class="f-size-26">{{ userInfo.deptName }}</view>
  32. <view class="ml-2 text-color-9">
  33. <view class="ml-2 text-color-9"> <u-icon name="arrow-right"></u-icon> </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="d-flex j-between px3 py2 border-bottom" @tap="forget">
  38. <view class="f-size-30 text-color-3">修改密码</view>
  39. <view class="d-flex a-center">
  40. <view class="ml-2 text-color-9"> <u-icon name="arrow-right"></u-icon> </view>
  41. </view>
  42. </view>
  43. <view class="d-flex j-between px3 py2 border-bottom" @tap="getOpenId">
  44. <view class="f-size-30 text-color-3">绑定微信</view>
  45. <view class="d-flex a-center">
  46. <view class="ml-2 text-color-9"> <u-icon name="arrow-right"></u-icon> </view>
  47. </view>
  48. </view>
  49. <!--<view class="d-flex j-between px3 py2 border-bottom" @tap="about">
  50. <view class="f-size-30 text-color-3">关于我们</view>
  51. <view class="d-flex a-center">
  52. <view class="ml-2 text-color-9"> <u-icon name="arrow-right"></u-icon> </view>
  53. </view>
  54. </view>-->
  55. <button
  56. class="main-color-bg text-color-white logout"
  57. @tap="logoutShow = true">退出登录</button>
  58. <u-modal
  59. v-model="logoutShow"
  60. :content="'确认退出登录?'"
  61. :show-cancel-button="true"
  62. @confirm="logout"
  63. ></u-modal>
  64. </view>
  65. </template>
  66. <script>
  67. export default {
  68. data() {
  69. return {
  70. logoutShow: false,
  71. myAvatar: '',
  72. openId: null,
  73. userInfo: {
  74. realName: null,
  75. deptName: null
  76. },
  77. form: {
  78. name: '张三',
  79. department: '技术部',
  80. pic: '../../static/images/user_pic.png'
  81. }
  82. };
  83. },
  84. onShow() {
  85. this.userInfo = this.$BaseTool.UserUtil.getUserInfo();
  86. this.myAvatar = this.$BaseTool.UserUtil.getFileUrl(this.userInfo.avatar);
  87. this.openId = this.userInfo.openId
  88. },
  89. methods: {
  90. myDefaultAvatar() {
  91. this.myAvatar = '/static/images/user_pic.png'
  92. },
  93. // editdepartment
  94. editDepartment() {
  95. uni.navigateTo({
  96. url: '../edit-name/edit-name?department=' + this.form.department
  97. });
  98. },
  99. // editName
  100. editName() {
  101. uni.navigateTo({
  102. url: '../edit-name/edit-name?name=' + this.form.name
  103. });
  104. },
  105. getOpenId() {
  106. // #ifdef H5
  107. this.$Http.getWechatRedirectUrl().then((res) => {
  108. uni.showToast({
  109. title: '跳转微信授权……',
  110. duration: 5000
  111. });
  112. window.location.href = res.data
  113. });
  114. // #endif
  115. // #ifndef H5
  116. uni.login({
  117. provider: 'weixin',
  118. success(res) {
  119. this.$Http.getWechatOpenId(res.code).then((res) => {
  120. uni.showToast({
  121. title: '授权成功,请重新登录'
  122. });
  123. this.logout();
  124. });
  125. }
  126. })
  127. // #endif
  128. },
  129. getSubscribe() {
  130. var tmplIds = ['3xLMrIa0X5yPiLaFk******rXqi9qPsvLUKKq4'] // 模板ID
  131. // #ifdef H5
  132. uni.showToast({
  133. title: '请从小程序登录后,订阅消息',
  134. icon: 'none'
  135. });
  136. // #endif
  137. // #ifndef H5
  138. uni.requestSubscribeMessage({
  139. tmplIds: tmplIds,
  140. success: (res) => { // 用户点击确定
  141. for (const key in res) {
  142. if (res[key] === 'accept') {
  143. uni.showToast({
  144. title: '已允许消息推送'
  145. })
  146. this.sendMessage(key)
  147. } else {
  148. }
  149. }
  150. },
  151. fail: (errMessage) => {
  152. console.log('订阅消息 失败 ', errMessage);
  153. }
  154. })
  155. // #endif
  156. },
  157. // 修改头像
  158. handlePic(flag) {
  159. console.log(111, flag, !flag)
  160. if (!flag) {
  161. return
  162. }
  163. const that = this
  164. uni.chooseImage({
  165. success(chooseImageRes) {
  166. const tempFilePaths = chooseImageRes.tempFilePaths
  167. const choseFileList = chooseImageRes.tempFiles
  168. // 校验文件
  169. for (const choseFile of choseFileList) {
  170. const item = choseFile.name
  171. if (that.$BaseTool.Object.isNotBlank(item) && item.length > 3) {
  172. const itemSub = item.substr(item.length - 3)
  173. if (itemSub !== 'PNG' &&
  174. itemSub !== 'png' &&
  175. itemSub !== 'peg' &&
  176. itemSub !== 'PEG' &&
  177. itemSub !== 'jpg' &&
  178. itemSub !== 'JPG' &&
  179. itemSub !== 'GIF' &&
  180. itemSub !== 'gif' &&
  181. itemSub !== 'bmp' &&
  182. itemSub !== 'BMP') {
  183. uni.showToast({ icon: 'none', title: '请上传图片' })
  184. return
  185. }
  186. }
  187. }
  188. uni.showLoading({ title: '正在上传', mask: true })
  189. try {
  190. this.$Http.uploadImageList(tempFilePaths).then(fileResult => {
  191. const imageListResult = []
  192. fileResult.forEach(item => {
  193. if (item != null) {
  194. imageListResult.push(item)
  195. }
  196. })
  197. if (imageListResult.length > 0) {
  198. that.imagesList = that.imagesList.concat(imageListResult)
  199. }
  200. }, () => {
  201. }).catch(err => console.log(err))
  202. .finally(function() {
  203. uni.hideLoading()
  204. })
  205. } catch (e) {
  206. uni.hideLoading()
  207. }
  208. }
  209. })
  210. },
  211. // 关于我们
  212. about() {
  213. uni.navigateTo({
  214. url: '/pages/about/about'
  215. });
  216. },
  217. // 忘记密码
  218. forget() {
  219. uni.navigateTo({
  220. url: '/pages/setting/forget-password'
  221. });
  222. },
  223. updateInfo() {
  224. uni.navigateTo({
  225. url: '/pages/setting/update-setting'
  226. });
  227. },
  228. // 退出登录
  229. logout() {
  230. uni.removeStorageSync('userInfo');
  231. uni.removeStorageSync('accessToken');
  232. uni.redirectTo({
  233. url: '/pages/login/login'
  234. });
  235. }
  236. }
  237. };
  238. </script>
  239. <style scoped>
  240. .logout {
  241. width: 600rpx;
  242. height: 100rpx;
  243. margin: 100rpx auto 0;
  244. border-radius: 80rpx;
  245. }
  246. </style>