bindOperator.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. <template>
  2. <view class="container login">
  3. <view class="login-form clearfix">
  4. <view class="login-input">
  5. <input type="text"
  6. v-model="bindLinkName"
  7. maxlength="30"
  8. class="input"
  9. placeholder="请输入姓名"
  10. />
  11. </view>
  12. </view>
  13. <view class="login-form clearfix">
  14. <view class="login-input">
  15. <input type="number"
  16. v-model="bindLinkPhone"
  17. maxlength="11"
  18. class="input"
  19. placeholder="请输入手机号"
  20. />
  21. </view>
  22. </view>
  23. <view class="login-form clearfix">
  24. <view class="login-input code">
  25. <input type="text"
  26. v-model="imageCode"
  27. maxlength="4"
  28. class="input"
  29. placeholder="请输入右侧图形验证码"
  30. />
  31. </view>
  32. <view class="login-input img-btn">
  33. <view class="vscodeimg">
  34. <image :src="imageCodeUrl" mode=""></image>
  35. </view>
  36. <view class="vscod-refresh" @click.stop="getVerificationCode">
  37. <text class="iconfont icon-shuaxin"></text>
  38. <text class="ref-text">刷新</text>
  39. </view>
  40. </view>
  41. </view>
  42. <view class="login-form clearfix">
  43. <view class="login-input code">
  44. <input type="number"
  45. v-model="mobildeCode"
  46. maxlength="6"
  47. class="input"
  48. placeholder="请输入短信验证码"
  49. />
  50. </view>
  51. <view class="login-input btn" :class="[isMobileDisabled ? 'disabled' : '']" >
  52. <button type="button"
  53. @click.stop="getMobileCodeFn"
  54. :disabled="isMobileDisabled"
  55. class="input">
  56. {{ mobileCodeText }}
  57. </button>
  58. </view>
  59. </view>
  60. <view class="login-form clearfix">
  61. <view class="login-btn" @click="bindWechatInfo">绑定并登录</view>
  62. </view>
  63. <view class="login-foot">
  64. <text class="foot-text">本操作会绑定您的微信,绑定后您可使用微信直接登录【采美采购商城】小程序。</text>
  65. </view>
  66. </view>
  67. </template>
  68. <script>
  69. import { mapState,mapMutations } from 'vuex'
  70. import authorize from '@/common/config/authorize.js'
  71. import { bindingWechat } from "@/api/use.js"
  72. import { getImageCode, getbindWechatCode } from "@/api/utils.js"
  73. export default{
  74. data() {
  75. return{
  76. bindMobile:'',
  77. bindLinkName:'', //用户姓名
  78. bindLinkPhone:'', //用户手机号
  79. mobildeCode:'', //手机验证码
  80. imageCode:'', //图形验证码
  81. imageCodeUrl:'', //图形验证码地址
  82. imageCodetoken:'', //图形校验token
  83. isMobileDisabled:false, //获取手机短信按钮
  84. count: '', //倒计时
  85. mobileCodeText: '获取验证码',
  86. codeTime: null,
  87. }
  88. },
  89. onLoad(option) {
  90. console.log(option)
  91. uni.setStorageSync('bind_id', option.userID);
  92. this.getVerificationCode()
  93. },
  94. methods:{
  95. ...mapMutations(['login']),
  96. bindWechatInfo(){
  97. if( this.bindLinkName == ''){
  98. this.$util.msg('请输入姓名',2000)
  99. return
  100. }
  101. if( this.bindLinkPhone == ''){
  102. this.$util.msg('请输入手机号',2000)
  103. return
  104. }
  105. if(!this.$reg.isMobile(this.bindLinkPhone)){
  106. this.$util.msg('请输入正确的手机号',2000)
  107. return
  108. }
  109. if( this.mobildeCode == ''){
  110. this.$util.msg('请输入手机验证码',2000)
  111. return
  112. }
  113. if(!this.$reg.isMobileCode(this.mobildeCode)){
  114. this.$util.msg('验证码格式不正确',2000)
  115. return
  116. }
  117. this.bindingWechatLogin()
  118. },
  119. getVerificationCode(){//图形验证
  120. getImageCode().then(res => {
  121. this.imageCodeUrl = res.data.baseImage
  122. this.imageCodetoken = res.data.token
  123. })
  124. },
  125. getMobileCodeFn(){//获取手机验证码
  126. if( this.bindLinkPhone == ''){
  127. this.$util.msg('请输入手机号',2000);
  128. return
  129. }
  130. if(!this.$reg.isMobile(this.bindLinkPhone)){
  131. this.$util.msg('请输入正确的手机号',2000);
  132. return
  133. }
  134. if( this.imageCode == ''){
  135. this.$util.msg('请输入图形验证码',2000);
  136. return
  137. }
  138. let params = {
  139. mobile:this.bindLinkPhone,
  140. mobileOrEmail:this.bindMobile,
  141. platformType:2,
  142. imgCode:this.imageCode,
  143. token:this.imageCodetoken,
  144. }
  145. this.isMobileDisabled = true;
  146. getbindWechatCode(params).then(res =>{
  147. const TIME_COUNT = 60;
  148. this.$util.msg('验证短信已发送',2000)
  149.       if (!this.codeTime) {
  150.         this.count = TIME_COUNT;
  151. this.isMobileDisabled = true;
  152.         this.codeTime = setInterval(() => {
  153.         if (this.count > 1 && this.count <= TIME_COUNT) {
  154.           this.count--
  155.           this.mobileCodeText = this.count +'s重新发送'
  156.          } else {
  157.           this.isMobileDisabled = false;
  158.           clearInterval(this.codeTime)
  159.           this.codeTime = null
  160. this.mobileCodeText = '获取验证码'
  161.          }
  162.         },1000)
  163.        }
  164. }).catch( res =>{
  165. this.$util.msg(res.msg,2000)
  166. this.isMobileDisabled = false;
  167. })
  168. },
  169. bindingWechatLogin(){//获取用户基本信息登录
  170. wx.getUserInfo({
  171. success: res => {
  172. console.log('useInfo:',res.userInfo)
  173. this.userInfo = res.userInfo;
  174. let params ={
  175. userID: uni.getStorageSync('bind_id'),
  176. mobile: this.bindLinkPhone,
  177. linkName: this.bindLinkName,
  178. verificationCode: this.mobildeCode,
  179. nickName: res.userInfo.nickName,
  180. headimgurl: res.userInfo.avatarUrl,
  181. }
  182. bindingWechat(params).then(response =>{
  183. this.login(response.data);
  184. uni.switchTab({
  185. url:'/pages/tabBar/user/user'
  186. })
  187. }).catch(response =>{
  188. this.$util.msg(response.msg,2000)
  189. })
  190. }
  191. })
  192. }
  193. },
  194. onShow() {
  195. //查看此微信用户是否已经授权过
  196. authorize.getSetting().then(res =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  197. if(res != 1){
  198. this.$api.navigateTo('/pages/authorization/authorization?type=3')
  199. }else{
  200. console.log('22222222222222')
  201. }
  202. })
  203. }
  204. }
  205. </script>
  206. <style lang="scss">
  207. .login{
  208. width: 100%;
  209. height: auto;
  210. border-top: 1px solid #F7F7F7;
  211. padding-top: 100rpx;
  212. .login-foot{
  213. width: 702rpx;
  214. height: 88rpx;
  215. padding: 0 24rpx;
  216. margin-top: 30rpx;
  217. .foot-text{
  218. font-size: 24rpx;
  219. line-height: 44rpx;
  220. color:$text-color;
  221. }
  222. }
  223. .login-form{
  224. width: 702rpx;
  225. height: auto;
  226. padding: 0 24rpx;
  227. .login-input{
  228. width: 654rpx;
  229. height: 40rpx;
  230. padding: 24rpx;
  231. margin-bottom: 20rpx;
  232. background: #F7F7F7;
  233. border-radius: 14rpx;
  234. display: flex;
  235. flex-direction: column;
  236. align-items: center;
  237. &.code{
  238. width: 370rpx;
  239. float: left;
  240. margin-right: 20rpx;
  241. }
  242. &.btn{
  243. width: 258rpx;
  244. height: 88rpx;
  245. padding: 0;
  246. float: left;
  247. background: $btn-confirm;
  248. .input{
  249. width: 258rpx;
  250. height: 88rpx;
  251. line-height: 88rpx;
  252. padding: 0;
  253. border-radius: 14rpx;
  254. color: #FFFFFF;
  255. background: $btn-confirm;
  256. }
  257. &.disabled{
  258. background: #F7F7F7;
  259. .input{
  260. background: #F7F7F7;
  261. color: #999999;
  262. }
  263. }
  264. }
  265. &.img-btn{
  266. width: 250rpx;
  267. height: 88rpx;
  268. padding: 0;
  269. float: left;
  270. background: #FFFFFF;
  271. display: block;
  272. .vscodeimg{
  273. width: 180rpx;
  274. height: 88rpx;
  275. float: left;
  276. display: flex;
  277. flex-direction: column;
  278. align-items: center;
  279. border-radius: 14rpx;
  280. image{
  281. width: 180rpx;
  282. height: 88rpx;
  283. border-radius: 14rpx;
  284. }
  285. }
  286. .vscod-refresh{
  287. width: 70rpx;
  288. float: right;
  289. display: flex;
  290. flex-direction: column;
  291. align-items: center;
  292. .icon-shuaxin{
  293. font-size: 48rpx;
  294. color: #333333;
  295. }
  296. .ref-text{
  297. font-size: 24rpx;
  298. color: #333333;
  299. }
  300. }
  301. }
  302. .input{
  303. width: 100%;
  304. height: 100%;
  305. background: #F7F7F7;
  306. font-size: $font-size-28;
  307. line-height: 40rpx;
  308. color: #333333;
  309. border-radius: 14rpx;
  310. }
  311. }
  312. }
  313. .login-btn{
  314. width: 702rpx;
  315. height: 88rpx;
  316. border-radius: 14rpx;
  317. font-size: $font-size-28;
  318. line-height: 88rpx;
  319. color: #FFFFFF;
  320. margin: 0 auto;
  321. text-align: center;
  322. background: $btn-confirm;
  323. margin-top: 100rpx;
  324. }
  325. .model-authorization{
  326. width: 100%;
  327. height: 100%;
  328. position: fixed;
  329. top: 0;
  330. left: 0;
  331. z-index: 999;
  332. .authorization{
  333. width: 518rpx;
  334. height: 320rpx;
  335. position: absolute;
  336. background: rgba(255,255,255,.7);
  337. left: 0;
  338. right: 0;
  339. bottom: 0;
  340. top: 0;
  341. margin: auto;
  342. .to-btn{
  343. position: absolute;
  344. top: 0;
  345. left: 0;
  346. right: 0;
  347. bottom: 0;
  348. margin: auto;
  349. width: 70%;
  350. height: 88rpx;
  351. font-size: $font-size-28;
  352. line-height: 88rpx;
  353. color: #FFFFFF;
  354. text-align: center;
  355. border-radius: 44rpx;
  356. }
  357. }
  358. }
  359. }
  360. </style>