password.vue 7.4 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. 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. if(self.loginType) {
  163. if(self.loginType=='detilType'){
  164. self.$api.redirectTo(`/pages/goods/product?id=${self.id}&page=2`);
  165. }else if(self.loginType=='search'){
  166. self.$api.redirectTo('/pages/search/search');
  167. }else if(self.loginType == 1){
  168. url ='/pages/tabBar/cart/cart'
  169. }else if(self.loginType == 2){
  170. url ='/pages/tabBar/user/user'
  171. }else {
  172. url ='/pages/tabBar/home/home'
  173. }
  174. uni.switchTab({
  175. url
  176. })
  177. } else if(self.listType) {
  178. self.$api.navToListPage({type:self.listType,value:self.listVal,lType:'4'});
  179. }
  180. } else {
  181. this.$util.msg(response.msg,3000);
  182. }
  183. })
  184. },
  185. //关闭未填邀请码弹窗
  186. hideToast(){
  187. self.isToast = false;
  188. },
  189. //关闭未授权用户授权提示弹窗
  190. hideModel(){
  191. self.isUserInfo = false;
  192. }
  193. }
  194. }
  195. </script>
  196. <style lang="scss">
  197. .login{
  198. width: 100%;
  199. height: auto;
  200. .model-warp.none{
  201. display: none;
  202. }
  203. .model-warp.show{
  204. display: block;
  205. }
  206. .login-main{
  207. width: 100%;
  208. display: flex;
  209. flex-direction: column;
  210. align-items: center;
  211. height: 198rpx;
  212. padding: 170rpx 0 60rpx 0;
  213. .logo{
  214. width: 138rpx;
  215. height: 118rpx;
  216. display: block;
  217. }
  218. .logo-text{
  219. font-size: 30rpx;
  220. line-height: 44rpx;
  221. color: $color-system;
  222. font-weight: 600;
  223. margin-top: 20rpx;
  224. }
  225. }
  226. .login-input{
  227. width: 654rpx;
  228. height: 40rpx;
  229. padding: 24rpx;
  230. margin: 0 auto;
  231. margin-bottom: 60rpx;
  232. background: #F7F7F7;
  233. border-radius: 14rpx;
  234. .input{
  235. width: 100%;
  236. height: 100%;
  237. background: #F7F7F7;
  238. font-size: $font-size-base;
  239. line-height: 40rpx;
  240. color: #333333;
  241. border-radius: 14rpx;
  242. }
  243. }
  244. .login-btn{
  245. width: 702rpx;
  246. height: 88rpx;
  247. border-radius: 14rpx;
  248. font-size: $font-size-base;
  249. line-height: 88rpx;
  250. color: #FFFFFF;
  251. margin: 0 auto;
  252. text-align: center;
  253. background: $btn-confirm;
  254. }
  255. .model-authorization{
  256. width: 100%;
  257. height: 100%;
  258. position: fixed;
  259. top: 0;
  260. left: 0;
  261. z-index: 999;
  262. .authorization{
  263. width: 518rpx;
  264. height: 320rpx;
  265. position: absolute;
  266. background: rgba(255,255,255,.7);
  267. left: 0;
  268. right: 0;
  269. bottom: 0;
  270. top: 0;
  271. margin: auto;
  272. .to-btn{
  273. position: absolute;
  274. top: 0;
  275. left: 0;
  276. right: 0;
  277. bottom: 0;
  278. margin: auto;
  279. width: 70%;
  280. height: 88rpx;
  281. font-size: $font-size-base;
  282. line-height: 88rpx;
  283. color: #FFFFFF;
  284. text-align: center;
  285. border-radius: 44rpx;
  286. }
  287. }
  288. }
  289. }
  290. </style>