login.vue 7.5 KB

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