login.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view class="container login">
  3. <view class="login-main">
  4. <image class="logo" src="../../static/login-logo@3x.png" mode=""></image>
  5. <text class="logo-text">生美/医美采购服务平台</text>
  6. </view>
  7. <view class="login-input">
  8. <input type="number"
  9. v-model="invitationCode"
  10. maxlength="6"
  11. class="input"
  12. placeholder="请输入邀请码"
  13. />
  14. </view>
  15. <view class="login-btn" @click="goLogin">授权登录</view>
  16. <view v-if="isToast" class="model-warp" >
  17. <view class="model-alert clearfix">
  18. <view class="alert-content">
  19. <view class="t-h1">{{toestText}}</view>
  20. <view class="t-p">请联系客服获取{{alertText}}后再登录,联系电话{{telPhone}}</view>
  21. </view>
  22. <view class="alert-btn">
  23. <view class="btn btn-confirm" @click="hideToast">确定</view>
  24. </view>
  25. </view>
  26. </view>
  27. <!-- 授权按钮 -->
  28. <view class="model-warp" :class="[isUserInfo===false ? 'none':'show']">
  29. <view class="model-alert">
  30. <view class="alert-content">
  31. <view class="t-p">采美采购商城需要获取您的微信授权才能正常提供服务</view>
  32. </view>
  33. <view class="alert-btn">
  34. <view class="btn btn-cancel" @click="hideModel">取消</view>
  35. <button type="primary" size="small" open-type="getUserInfo" lang="zh_CN" @getuserinfo="getuserinfo" class="btn btn-confirm">授权</button>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. </template>
  41. <script>
  42. import { mapMutations } from 'vuex';
  43. import authorize from '@/common/config/authorize.js'
  44. import { invitationCodeLogin } from '@/api/use.js'
  45. var self;
  46. export default{
  47. data() {
  48. return{
  49. invitationCode:'', //获取用户登录的邀请码
  50. isToast:false, //控制显示未输入邀请码提示
  51. isUserInfo:false, //控制显示授权弹窗
  52. nickName:'', //存储用户名
  53. userInfo:'', //存储微信用户授权信息
  54. isSuccess:false,
  55. toestText:'',
  56. telPhone:'',
  57. loginType:'', //跳转类型
  58. alertText:'',
  59. listType: '',
  60. listVal: '',
  61. detilType:'',
  62. id:''//商品ID
  63. }
  64. },
  65. onLoad(option) {
  66. console.log(option)
  67. self = this;
  68. self.loginType = option.type;
  69. self.id = option.id
  70. if(option.listType) {
  71. self.listType = option.listType;
  72. self.listVal = option.listVal;
  73. }
  74. },
  75. methods:{
  76. ...mapMutations(['login']),
  77. goLogin() {
  78. if( this.invitationCode == ''){
  79. this.$util.msg('请输入邀请码',2000)
  80. return
  81. }
  82. //查看此微信用户是否已经授权过
  83. authorize.getSetting().then(res =>{
  84. // console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  85. if(res == 2){
  86. this.isUserInfo = true
  87. }else{
  88. this.isUserInfo = false
  89. this.wxGetUserInfo()
  90. }
  91. })
  92. },
  93. //授权登录
  94. getuserinfo: function (e) {
  95. if (e.detail.userInfo) {
  96. self.wxGetUserInfo()
  97. }else{
  98. //用户按了拒绝按钮
  99. uni.showModal({
  100. content: '获取用户信息失败,请允许授权后才能继续使用小程序哦~',
  101. showCancel: false,
  102. confirmText: '授权',
  103. success: function (res) {
  104. if (res.confirm) {
  105. uni.openSetting({
  106. success: res => {
  107. // console.log(res.authSetting)
  108. },
  109. fail: res => {
  110. // console.log(res)
  111. }
  112. })
  113. }
  114. }
  115. })
  116. }
  117. },
  118. wxGetUserInfo(){
  119. authorize.getCode('weixin').then(wechatcode =>{
  120. wx.getUserInfo({
  121. success: res => {
  122. // console.log('useInfo:',res.userInfo)
  123. self.userInfo = res.userInfo;
  124. let params ={
  125. userID:this.userID,
  126. invitationCode:this.invitationCode,
  127. nickName:res.userInfo.nickName,
  128. headimgurl:res.userInfo.avatarUrl,
  129. }
  130. invitationCodeLogin(params).then(response =>{
  131. self.isUserInfo = false
  132. this.goUserLogininit()
  133. }).catch(response =>{
  134. this.$util.msg(response.msg,2000)
  135. this.isUserInfo = false
  136. })
  137. }
  138. });
  139. })
  140. },
  141. goUserLogininit(){
  142. let url;
  143. if(this.loginType) {
  144. if(this.loginType=='detilType'){
  145. this.$api.redirectTo(`/pages/goods/product?id=${this.id}&page=2`);
  146. }else if(this.loginType=='search'){
  147. this.$api.redirectTo('/pages/search/search');
  148. }else if(this.loginType == 1){
  149. url ='/pages/tabBar/cart/cart'
  150. }else if(this.loginType == 4){
  151. url ='/pages/tabBar/user/user'
  152. }else {
  153. url ='/pages/tabBar/home/home'
  154. }
  155. uni.switchTab({
  156. url
  157. })
  158. } else if(this.listType) {
  159. this.$api.navToListPage({type:this.listType,value:this.listVal,lType:'4'});
  160. }
  161. },
  162. //关闭未填邀请码弹窗
  163. hideToast(){
  164. self.isToast = false;
  165. },
  166. //关闭未授权用户授权提示弹窗
  167. hideModel(){
  168. self.isUserInfo = false;
  169. }
  170. }
  171. }
  172. </script>
  173. <style lang="scss">
  174. .login{
  175. width: 100%;
  176. height: auto;
  177. .model-warp.none{
  178. display: none;
  179. }
  180. .model-warp.show{
  181. display: block;
  182. }
  183. .login-main{
  184. width: 100%;
  185. display: flex;
  186. flex-direction: column;
  187. align-items: center;
  188. height: 198rpx;
  189. padding: 170rpx 0 60rpx 0;
  190. .logo{
  191. width: 138rpx;
  192. height: 118rpx;
  193. display: block;
  194. }
  195. .logo-text{
  196. font-size: 30rpx;
  197. line-height: 44rpx;
  198. color: $color-system;
  199. font-weight: 600;
  200. margin-top: 20rpx;
  201. }
  202. }
  203. .login-input{
  204. width: 654rpx;
  205. height: 40rpx;
  206. padding: 24rpx;
  207. margin: 0 auto;
  208. margin-bottom: 60rpx;
  209. background: #F7F7F7;
  210. border-radius: 14rpx;
  211. .input{
  212. width: 100%;
  213. height: 100%;
  214. background: #F7F7F7;
  215. font-size: $font-size-28;
  216. line-height: 40rpx;
  217. color: #333333;
  218. border-radius: 14rpx;
  219. }
  220. }
  221. .login-btn{
  222. width: 702rpx;
  223. height: 88rpx;
  224. border-radius: 14rpx;
  225. font-size: $font-size-28;
  226. line-height: 88rpx;
  227. color: #FFFFFF;
  228. margin: 0 auto;
  229. text-align: center;
  230. background: $btn-confirm;
  231. }
  232. .model-authorization{
  233. width: 100%;
  234. height: 100%;
  235. position: fixed;
  236. top: 0;
  237. left: 0;
  238. z-index: 999;
  239. .authorization{
  240. width: 518rpx;
  241. height: 320rpx;
  242. position: absolute;
  243. background: rgba(255,255,255,.7);
  244. left: 0;
  245. right: 0;
  246. bottom: 0;
  247. top: 0;
  248. margin: auto;
  249. .to-btn{
  250. position: absolute;
  251. top: 0;
  252. left: 0;
  253. right: 0;
  254. bottom: 0;
  255. margin: auto;
  256. width: 70%;
  257. height: 88rpx;
  258. font-size: $font-size-28;
  259. line-height: 88rpx;
  260. color: #FFFFFF;
  261. text-align: center;
  262. border-radius: 44rpx;
  263. }
  264. }
  265. }
  266. }
  267. </style>