bind.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view v-if="code">
  3. <view class="hangkuai">允许小程序使用我的</view>
  4. <view class="hangkuai">
  5. <text>向我发送服务通知</text>
  6. <img src="@/static/open.png">
  7. </view>
  8. <view class="hangkuai">
  9. <text>接受工单通知</text>
  10. <img src="@/static/open.png">
  11. </view>
  12. <view class="zhuangtai" v-if="bindStatus != 0"><text>{{ bindStatusName[bindStatus] }}</text></view>
  13. <view class="anniuyangs" v-if="bindStatus == 1 && wx_url != ''">
  14. <view @click="confirm">授权接收订阅消息</view>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. data() {
  21. return {
  22. appid: "",
  23. code: "",
  24. bindStatusName: ["", "未授权", "已授权"],
  25. bindStatus: 0,
  26. wx_url: ""
  27. }
  28. },
  29. onLoad({ appid, code, state }) {
  30. this.appid = appid || state
  31. this.code = code
  32. if (appid && !code) {
  33. window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.appid
  34. }&redirect_uri=${location.href
  35. }&response_type=code&scope=snsapi_userinfo&state=${this.appid
  36. }#wechat_redirect`;
  37. } else {
  38. // 获取绑定状态
  39. this.$api.post('/user/pub/auth', {
  40. code: this.code,
  41. pubAppId: this.appid,
  42. }).then(res => {
  43. this.bindStatus = res.data ? 1 : 2;
  44. this.wx_url = res.data;
  45. })
  46. }
  47. },
  48. methods: {
  49. confirm() {
  50. window.open(this.wx_url)
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. page {
  57. background: #fff;
  58. }
  59. .hangkuai {
  60. width: 100%;
  61. height: 90rpx;
  62. box-sizing: border-box;
  63. padding: 16rpx;
  64. display: flex;
  65. justify-content: space-between;
  66. align-items: center;
  67. img {
  68. height: 38rpx;
  69. }
  70. &:nth-child(1) {
  71. background: #efefef;
  72. }
  73. &:nth-child(2),
  74. &:nth-child(3) {
  75. border-bottom: 1rpx solid #eee;
  76. }
  77. }
  78. .zhuangtai {
  79. width: 100%;
  80. height: 140rpx;
  81. display: flex;
  82. justify-content: center;
  83. align-items: center;
  84. font-weight: bold;
  85. }
  86. .anniuyangs {
  87. width: 100%;
  88. height: 100rpx;
  89. box-sizing: border-box;
  90. padding: 16rpx;
  91. view {
  92. width: 100%;
  93. height: 100%;
  94. display: flex;
  95. justify-content: center;
  96. align-items: center;
  97. background: #00e266;
  98. border-radius: 6rpx;
  99. color: #fff;
  100. }
  101. }
  102. </style>