login.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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. invitationCodeLogin({invitationCode:this.invitationCode}).then(response =>{
  79. //查看此微信用户是否已经授权过
  80. authorize.getSetting().then(res =>{
  81. // console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  82. if(res == 2){
  83. this.isUserInfo = true
  84. }else{
  85. this.isUserInfo = false
  86. this.wxGetUserInfo()
  87. }
  88. })
  89. }).catch(response =>{
  90. if(res.code =='-2'){
  91. this.toestText ='邀请码已失效';
  92. this.alertText ='新邀请码';
  93. this.telPhone = res.msg;
  94. this.isToast = true;
  95. }else if(res.code =='-3'){
  96. this.toestText ='邀请码已被使用';
  97. this.alertText ='新邀请码';
  98. this.telPhone = res.msg;
  99. this.isToast = true;
  100. }else{
  101. this.$util.msg(response.msg,2000)
  102. this.isUserInfo = false
  103. }
  104. })
  105. },
  106. //授权登录
  107. getuserinfo: function (e) {
  108. if (e.detail.userInfo) {
  109. self.wxGetUserInfo()
  110. }else{
  111. //用户按了拒绝按钮
  112. uni.showModal({
  113. content: '获取用户信息失败,请允许授权后才能继续使用小程序哦~',
  114. showCancel: false,
  115. confirmText: '授权',
  116. success: function (res) {
  117. if (res.confirm) {
  118. uni.openSetting({
  119. success: res => {
  120. // console.log(res.authSetting)
  121. },
  122. fail: res => {
  123. // console.log(res)
  124. }
  125. })
  126. }
  127. }
  128. })
  129. }
  130. },
  131. wxGetUserInfo(){
  132. authorize.getCode('weixin').then(wechatcode =>{
  133. wx.getUserInfo({
  134. success: res => {
  135. // console.log('useInfo:',res.userInfo)
  136. self.userInfo = res.userInfo;
  137. let params ={
  138. code:wechatcode,
  139. nickName:res.userInfo.nickName,
  140. invitationCode:self.invitationCode,
  141. userOrganizeID:self.userOrganizeID,
  142. }
  143. self.goUserLogininit(params);
  144. }
  145. });
  146. })
  147. },
  148. goUserLogininit(params){
  149. self.$api.lodingGet('/login/register',params, response => {
  150. // console.log(response)
  151. if (response.code == "1") {
  152. self.isUserInfo = false;
  153. self.login(self.userInfo);
  154. let user_key = {code:response.code,openid:response.data.openid,userID:response.data.userID}
  155. uni.setStorageSync('cookieKey','JSESSIONID='+response.data.sessionId);
  156. this.$store.commit('updateStatus',user_key)
  157. let url;
  158. uni.switchTab({
  159. url:'/pages/tabBar/user/user'
  160. })
  161. // if(self.loginType) {
  162. // if(self.loginType=='detilType'){
  163. // self.$api.redirectTo(`/pages/goods/product?id=${self.id}&page=2`);
  164. // }else if(self.loginType=='search'){
  165. // self.$api.redirectTo('/pages/search/search');
  166. // }else if(self.loginType == 1){
  167. // url ='/pages/tabBar/cart/cart'
  168. // }else if(self.loginType == 2){
  169. // url ='/pages/tabBar/user/user'
  170. // }else {
  171. // url ='/pages/tabBar/home/home'
  172. // }
  173. // uni.switchTab({
  174. // url
  175. // })
  176. // } else if(self.listType) {
  177. // self.$api.navToListPage({type:self.listType,value:self.listVal,lType:'4'});
  178. // }
  179. } else {
  180. this.$util.msg(response.msg,3000);
  181. }
  182. })
  183. },
  184. //关闭未填邀请码弹窗
  185. hideToast(){
  186. self.isToast = false;
  187. },
  188. //关闭未授权用户授权提示弹窗
  189. hideModel(){
  190. self.isUserInfo = false;
  191. }
  192. }
  193. }
  194. </script>
  195. <style lang="scss">
  196. .login{
  197. width: 100%;
  198. height: auto;
  199. .model-warp.none{
  200. display: none;
  201. }
  202. .model-warp.show{
  203. display: block;
  204. }
  205. .login-main{
  206. width: 100%;
  207. display: flex;
  208. flex-direction: column;
  209. align-items: center;
  210. height: 198rpx;
  211. padding: 170rpx 0 60rpx 0;
  212. .logo{
  213. width: 138rpx;
  214. height: 118rpx;
  215. display: block;
  216. }
  217. .logo-text{
  218. font-size: 30rpx;
  219. line-height: 44rpx;
  220. color: $color-system;
  221. font-weight: 600;
  222. margin-top: 20rpx;
  223. }
  224. }
  225. .login-input{
  226. width: 654rpx;
  227. height: 40rpx;
  228. padding: 24rpx;
  229. margin: 0 auto;
  230. margin-bottom: 60rpx;
  231. background: #F7F7F7;
  232. border-radius: 14rpx;
  233. .input{
  234. width: 100%;
  235. height: 100%;
  236. background: #F7F7F7;
  237. font-size: $font-size-28;
  238. line-height: 40rpx;
  239. color: #333333;
  240. border-radius: 14rpx;
  241. }
  242. }
  243. .login-btn{
  244. width: 702rpx;
  245. height: 88rpx;
  246. border-radius: 14rpx;
  247. font-size: $font-size-28;
  248. line-height: 88rpx;
  249. color: #FFFFFF;
  250. margin: 0 auto;
  251. text-align: center;
  252. background: $btn-confirm;
  253. }
  254. .model-authorization{
  255. width: 100%;
  256. height: 100%;
  257. position: fixed;
  258. top: 0;
  259. left: 0;
  260. z-index: 999;
  261. .authorization{
  262. width: 518rpx;
  263. height: 320rpx;
  264. position: absolute;
  265. background: rgba(255,255,255,.7);
  266. left: 0;
  267. right: 0;
  268. bottom: 0;
  269. top: 0;
  270. margin: auto;
  271. .to-btn{
  272. position: absolute;
  273. top: 0;
  274. left: 0;
  275. right: 0;
  276. bottom: 0;
  277. margin: auto;
  278. width: 70%;
  279. height: 88rpx;
  280. font-size: $font-size-28;
  281. line-height: 88rpx;
  282. color: #FFFFFF;
  283. text-align: center;
  284. border-radius: 44rpx;
  285. }
  286. }
  287. }
  288. }
  289. </style>