index.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <view class="notify-page">
  3. <view class="notify-body">
  4. <!-- 步骤 1:关注服务号 -->
  5. <view class="step-card" :class="{ 'is-done': step1Done }">
  6. <view class="step-hd">
  7. <view class="step-num">1</view>
  8. <view class="step-main">
  9. <view class="step-title">关注服务号</view>
  10. <view class="step-desc">
  11. 关注后才能接收微信模板消息。可跳转服务号主页,或长按识别二维码。
  12. </view>
  13. </view>
  14. <text class="step-badge" :class="{ 'is-done': step1Done }">
  15. {{ step1Done ? '已完成' : '未完成' }}
  16. </text>
  17. </view>
  18. <view class="step-actions">
  19. <button class="btn btn-primary" @click="onFollow">
  20. {{ step1Done ? '重新打开关注页' : '去关注' }}
  21. </button>
  22. <view v-if="showQr && !step1Done" class="qr-box">
  23. <image
  24. class="qr-img"
  25. :src="mpQrcodeUrl"
  26. mode="aspectFit"
  27. show-menu-by-longpress
  28. />
  29. <text class="qr-tip">长按识别关注</text>
  30. <button class="btn btn-ghost" @click="onConfirmFollowed">我已关注</button>
  31. </view>
  32. </view>
  33. </view>
  34. <!-- 步骤 2:绑定账号 -->
  35. <view class="step-card" :class="{ 'is-done': step2Done }">
  36. <view class="step-hd">
  37. <view class="step-num">2</view>
  38. <view class="step-main">
  39. <view class="step-title">绑定当前账号</view>
  40. <view class="step-desc">
  41. 将服务号身份与系统账号关联,审批待办 / 抄送才能推送到你。
  42. </view>
  43. </view>
  44. <text class="step-badge" :class="{ 'is-done': step2Done }">
  45. {{ step2Done ? '已完成' : '未完成' }}
  46. </text>
  47. </view>
  48. <view class="step-actions">
  49. <button
  50. class="btn btn-primary"
  51. :disabled="!step1Done || step2Done"
  52. @click="onBind"
  53. >
  54. {{
  55. step2Done
  56. ? '已绑定'
  57. : step1Done
  58. ? '去绑定'
  59. : '请先完成步骤 1'
  60. }}
  61. </button>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </template>
  67. <script>
  68. import {
  69. fetchMpBindStatus,
  70. getUser,
  71. forceRelogin,
  72. getToken
  73. } from '../../../utils/auth.js'
  74. import {
  75. isFollowConfirmed,
  76. setFollowConfirmed,
  77. resolveStepDone
  78. } from '../../../utils/mp-follow-confirm.js'
  79. import { MP_GH_USERNAME, MP_QRCODE_URL } from '../../../utils/config.js'
  80. function currentUserId() {
  81. const u = getUser() || {}
  82. return u.id || u.userId || u.username || ''
  83. }
  84. export default {
  85. data() {
  86. return {
  87. bound: false,
  88. followConfirmed: false,
  89. showQr: false,
  90. mpQrcodeUrl: MP_QRCODE_URL,
  91. step1Done: false,
  92. step2Done: false
  93. }
  94. },
  95. onShow() {
  96. if (!getToken()) {
  97. forceRelogin('请先登录')
  98. return
  99. }
  100. this.followConfirmed = isFollowConfirmed(currentUserId())
  101. this.refreshBind()
  102. },
  103. methods: {
  104. applySteps() {
  105. const r = resolveStepDone({
  106. bound: this.bound,
  107. followConfirmed: this.followConfirmed
  108. })
  109. this.step1Done = r.step1Done
  110. this.step2Done = r.step2Done
  111. },
  112. async refreshBind() {
  113. try {
  114. const res = await fetchMpBindStatus()
  115. this.bound = !!(res && res.bound)
  116. } catch (_) {
  117. this.bound = false
  118. }
  119. this.applySteps()
  120. },
  121. onFollow() {
  122. const username = (MP_GH_USERNAME || '').trim()
  123. const openProfile =
  124. typeof wx !== 'undefined' && typeof wx.openOfficialAccountProfile === 'function'
  125. if (openProfile && username) {
  126. wx.openOfficialAccountProfile({
  127. username,
  128. fail: () => {
  129. this.showQr = true
  130. }
  131. })
  132. return
  133. }
  134. this.showQr = true
  135. },
  136. onConfirmFollowed() {
  137. setFollowConfirmed(currentUserId(), true)
  138. this.followConfirmed = true
  139. this.showQr = false
  140. this.applySteps()
  141. uni.showToast({ title: '已标记关注', icon: 'none' })
  142. },
  143. onBind() {
  144. if (!this.step1Done || this.step2Done) return
  145. uni.navigateTo({ url: '/pages/oa/mp-bind/index' })
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang="scss" scoped>
  151. .notify-page {
  152. min-height: 100vh;
  153. background: #f5f8f7;
  154. box-sizing: border-box;
  155. }
  156. .notify-body {
  157. padding: 28rpx 24rpx 56rpx;
  158. }
  159. .step-card {
  160. background: #fff;
  161. border: 1px solid #dcebe4;
  162. border-radius: 28rpx;
  163. padding: 28rpx;
  164. margin-bottom: 20rpx;
  165. &.is-done {
  166. border-color: #b7ebcf;
  167. background: linear-gradient(180deg, #f6fffb 0%, #fff 60%);
  168. }
  169. }
  170. .step-hd {
  171. display: flex;
  172. align-items: flex-start;
  173. gap: 20rpx;
  174. }
  175. .step-num {
  176. width: 56rpx;
  177. height: 56rpx;
  178. border-radius: 50%;
  179. background: #0a9f6d;
  180. color: #fff;
  181. display: flex;
  182. align-items: center;
  183. justify-content: center;
  184. font-size: 28rpx;
  185. font-weight: 700;
  186. flex-shrink: 0;
  187. }
  188. .step-card.is-done .step-num {
  189. background: #189b65;
  190. }
  191. .step-main {
  192. flex: 1;
  193. min-width: 0;
  194. }
  195. .step-title {
  196. font-size: 30rpx;
  197. font-weight: 700;
  198. line-height: 1.35;
  199. color: #1f2a26;
  200. }
  201. .step-desc {
  202. margin-top: 8rpx;
  203. font-size: 24rpx;
  204. color: #6b7b74;
  205. line-height: 1.5;
  206. }
  207. .step-badge {
  208. margin-left: auto;
  209. font-size: 22rpx;
  210. padding: 4rpx 16rpx;
  211. border-radius: 999rpx;
  212. background: #eef2f0;
  213. color: #6b7b74;
  214. flex-shrink: 0;
  215. line-height: 1.4;
  216. &.is-done {
  217. background: #e9f9f2;
  218. color: #087f57;
  219. }
  220. }
  221. .step-actions {
  222. margin-top: 24rpx;
  223. padding-left: 76rpx;
  224. }
  225. .btn {
  226. appearance: none;
  227. border: 0;
  228. border-radius: 20rpx;
  229. padding: 20rpx 28rpx;
  230. font-size: 28rpx;
  231. font-weight: 600;
  232. min-height: 80rpx;
  233. line-height: 1.3;
  234. box-sizing: border-box;
  235. &::after {
  236. border: none;
  237. }
  238. }
  239. .btn-primary {
  240. background: #0a9f6d;
  241. color: #fff;
  242. width: 100%;
  243. &[disabled] {
  244. background: #a7d7c4;
  245. color: #fff;
  246. }
  247. }
  248. .btn-ghost {
  249. margin-top: 20rpx;
  250. background: #fff;
  251. color: #087f57;
  252. border: 1px solid #dcebe4;
  253. width: 100%;
  254. }
  255. .qr-box {
  256. margin-top: 20rpx;
  257. padding: 24rpx;
  258. border-radius: 24rpx;
  259. border: 1px dashed #a7f3d0;
  260. background: #f8fffb;
  261. text-align: center;
  262. }
  263. .qr-img {
  264. display: block;
  265. width: 280rpx;
  266. height: 280rpx;
  267. margin: 0 auto;
  268. border-radius: 16rpx;
  269. background: #fff;
  270. }
  271. .qr-tip {
  272. display: block;
  273. margin-top: 16rpx;
  274. font-size: 24rpx;
  275. color: #6b7b74;
  276. }
  277. </style>