menu.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <template>
  2. <view>
  3. <view class="margin-top grid col-3 padding-sm">
  4. <view class="padding-sm" v-for="(item,index) in colorList" :key="index">
  5. <view class="padding radius text-center shadow-blur" :class="'bg-' + item.name" @click="onItemClick(item)">
  6. <view class="text-lg">{{item.title}}</view>
  7. </view>
  8. </view>
  9. </view>
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. data() {
  15. return {
  16. colorList: [{
  17. title: '质量反馈',
  18. name: 'red',
  19. event: 'toList',
  20. }, {
  21. title: '退出登录',
  22. name: 'grey',
  23. event: 'logout',
  24. }]
  25. }
  26. },
  27. mounted() {
  28. //#ifdef MP-WEIXIN
  29. wx.hideHomeButton() //隐藏微信小程序的返回主页按钮
  30. //#endif
  31. },
  32. onLoad() {
  33. uni.getStorage({
  34. key: 'token',
  35. fail() {
  36. //从缓存中未获取到token失败时跳转登录界面
  37. uni.redirectTo({
  38. url: '../login/login'
  39. })
  40. }
  41. });
  42. },
  43. methods: {
  44. onItemClick(e) {
  45. if (e.event == undefined) {
  46. uni.showToast({
  47. title: '当前菜单项未设置点击事件!',
  48. icon: 'none'
  49. })
  50. } else {
  51. //触发菜单项的点击事件
  52. this[e.event]();
  53. }
  54. },
  55. toList() {
  56. //跳转值质量反馈列表页面
  57. uni.navigateTo({
  58. url: "../billlist/billlist"
  59. });
  60. },
  61. logout() {
  62. //图片已上传至服务器,询问用户是否确定删除
  63. uni.showModal({
  64. title: '提示',
  65. content: '是否确定要退出登录?',
  66. cancelText: '否',
  67. confirmText: '是',
  68. success: result => {
  69. if (result.confirm) {
  70. //清空token缓存
  71. uni.removeStorage({
  72. key: 'token',
  73. success: function(res) {
  74. //清空token缓存后,跳转至登录界面
  75. uni.redirectTo({
  76. url: '../login/login'
  77. })
  78. },
  79. fail() {
  80. //从清空token缓存失败时提示
  81. uni.showToast({
  82. title: '退出登录失败,原因是:未能清空token缓存!',
  83. icon: 'none'
  84. })
  85. }
  86. });
  87. }
  88. }
  89. })
  90. }
  91. }
  92. }
  93. </script>
  94. <style>
  95. </style>