login-accont.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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-form">
  8. <view class="login-input">
  9. <input type="number"
  10. v-model="accountCode"
  11. maxlength="30"
  12. class="input"
  13. placeholder="请输入邮箱/手机号"
  14. />
  15. </view>
  16. <view class="login-input">
  17. <input v-show="isShowEye" type="text" v-model="password" maxlength="18" class="input" placeholder="请输入密码" autocomplete="new-password"/>
  18. <input v-show="!isShowEye" type="password" v-model="password" :password="true" maxlength="18" class="input" placeholder="请输入密码" autocomplete="new-password"/>
  19. <view class="iconfont" :class="isShowEye ? iconEyen : iconEyes" @click="passwordClick"></view>
  20. </view>
  21. <view class="login-input link">
  22. <view class="login-reg" @click.stop="this.$api.navigateTo('/pages/user-module/register')">免费注册</view>
  23. <view class="login-pwd" @click.stop="this.$api.navigateTo('/pages/user-module/password')">忘记密码?</view>
  24. </view>
  25. </view>
  26. <view class="login-btn" @click="goLogin">登录</view>
  27. <view class="login-btn-last" @click.stop="this.$api.navigateTo('/pages/user-module/login')">授权登录</view>
  28. <view v-if="isToast" class="model-warp" >
  29. <view class="model-alert clearfix">
  30. <view class="alert-content">
  31. <view class="t-h1">{{toestText}}</view>
  32. <view class="t-p">请联系客服获取{{alertText}}后再登录,联系电话{{telPhone}}</view>
  33. </view>
  34. <view class="alert-btn">
  35. <view class="btn btn-confirm" @click="hideToast">确定</view>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 授权按钮 -->
  40. <view class="model-warp" :class="[isUserInfo===false ? 'none':'show']">
  41. <view class="model-alert">
  42. <view class="alert-content">
  43. <view class="t-p">采美采购商城需要获取您的微信授权才能正常提供服务</view>
  44. </view>
  45. <view class="alert-btn">
  46. <view class="btn btn-cancel" @click="hideModel">取消</view>
  47. <button type="primary" size="small" open-type="getUserInfo" lang="zh_CN" @getuserinfo="getuserinfo" class="btn btn-confirm">授权</button>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import { mapMutations } from 'vuex';
  55. import authorize from '@/common/config/authorize.js'
  56. var self;
  57. export default{
  58. data() {
  59. return{
  60. isShowEye:false,
  61. iconEyes:'icon-yanjing_yincang_o',
  62. iconEyen:'icon-yanjing_xianshi_o',
  63. accountCode:'', //用户登录账号
  64. password:'', //用户登录密码
  65. isToast:false, //控制显示未输入邀请码提示
  66. isUserInfo:false,//控制显示授权弹窗
  67. nickName:'', //存储用户名
  68. userInfo:'', //存储微信用户授权信息
  69. isSuccess:false,
  70. toestText:'',
  71. telPhone:'',
  72. loginType:'', //跳转类型
  73. alertText:'',
  74. listType: '',
  75. listVal: '',
  76. detilType:'',
  77. id:''//商品ID
  78. }
  79. },
  80. onLoad(option) {
  81. console.log(option)
  82. self = this;
  83. self.loginType = option.type;
  84. self.id = option.id
  85. if(option.listType) {
  86. self.listType = option.listType;
  87. self.listVal = option.listVal;
  88. }
  89. },
  90. methods:{
  91. ...mapMutations(['login']),
  92. goLogin() {
  93. if(this.accountCode === ""){
  94. this.$util.msg('请输入账户名',3000);
  95. return
  96. }
  97. if(this.password === ""){
  98. this.$util.msg('请输入密码',3000);
  99. return
  100. }
  101. self.$api.get('/login/isEnabled',{userOrganizeID:self.userOrganizeID,invitationCode:self.invitationCode}, res => {
  102. if (res.code == "1") {
  103. //查看此微信用户是否已经授权过
  104. authorize.getSetting().then(res =>{
  105. // console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  106. if(res == 2){
  107. self.isUserInfo = true
  108. }else{
  109. self.isUserInfo = false
  110. self.wxGetUserInfo()
  111. }
  112. })
  113. }else if(res.code =='0'){
  114. self.toestText ='请输入邀请码';
  115. self.alertText ='邀请码';
  116. self.telPhone = res.msg;
  117. self.isToast = true;
  118. }else if(res.code =='-2'){
  119. self.toestText ='邀请码已失效';
  120. self.alertText ='新邀请码';
  121. self.telPhone = res.msg;
  122. self.isToast = true;
  123. }else if(res.code =='-3'){
  124. self.toestText ='邀请码已被使用';
  125. self.alertText ='新邀请码';
  126. self.telPhone = res.msg;
  127. self.isToast = true;
  128. }else{
  129. uni.showToast({icon:'none', title: res.msg, duration: 3000});
  130. self.isUserInfo = false
  131. }
  132. })
  133. },
  134. //授权登录
  135. getuserinfo: function (e) {
  136. if (e.detail.userInfo) {
  137. self.wxGetUserInfo()
  138. }else{
  139. //用户按了拒绝按钮
  140. uni.showModal({
  141. content: '获取用户信息失败,请允许授权后才能继续使用小程序哦~',
  142. showCancel: false,
  143. confirmText: '授权',
  144. success: function (res) {
  145. if (res.confirm) {
  146. uni.openSetting({
  147. success: res => {
  148. // console.log(res.authSetting)
  149. },
  150. fail: res => {
  151. // console.log(res)
  152. }
  153. })
  154. }
  155. }
  156. })
  157. }
  158. },
  159. wxGetUserInfo(){
  160. authorize.getCode('weixin').then(wechatcode =>{
  161. wx.getUserInfo({
  162. success: res => {
  163. // console.log('useInfo:',res.userInfo)
  164. self.userInfo = res.userInfo;
  165. let params ={
  166. code:wechatcode,
  167. nickName:res.userInfo.nickName,
  168. invitationCode:self.invitationCode,
  169. userOrganizeID:self.userOrganizeID,
  170. }
  171. self.goUserLogininit(params);
  172. }
  173. });
  174. })
  175. },
  176. goUserLogininit(params){
  177. self.$api.lodingGet('/login/register',params, response => {
  178. // console.log(response)
  179. if (response.code == "1") {
  180. self.isUserInfo = false;
  181. self.login(self.userInfo);
  182. let user_key = {code:response.code,openid:response.data.openid,userID:response.data.userID}
  183. uni.setStorageSync('cookieKey','JSESSIONID='+response.data.sessionId);
  184. this.$store.commit('updateStatus',user_key)
  185. let url;
  186. if(self.loginType) {
  187. if(self.loginType=='detilType'){
  188. self.$api.redirectTo(`/pages/goods/product?id=${self.id}&page=2`);
  189. }else if(self.loginType=='search'){
  190. self.$api.redirectTo('/pages/search/search');
  191. }else if(self.loginType == 1){
  192. url ='/pages/tabBar/cart/cart'
  193. }else if(self.loginType == 2){
  194. url ='/pages/tabBar/user/user'
  195. }else {
  196. url ='/pages/tabBar/home/home'
  197. }
  198. uni.switchTab({
  199. url
  200. })
  201. } else if(self.listType) {
  202. self.$api.navToListPage({type:self.listType,value:self.listVal,lType:'4'});
  203. }
  204. } else {
  205. this.$util.msg(response.msg,3000);
  206. }
  207. })
  208. },
  209. //关闭未填邀请码弹窗
  210. hideToast(){
  211. self.isToast = false;
  212. },
  213. //关闭未授权用户授权提示弹窗
  214. hideModel(){
  215. self.isUserInfo = false;
  216. },
  217. passwordClick() { //密码显隐操作
  218. this.isShowEye = !this.isShowEye;
  219. },
  220. }
  221. }
  222. </script>
  223. <style lang="scss">
  224. .login{
  225. width: 100%;
  226. height: auto;
  227. .model-warp.none{
  228. display: none;
  229. }
  230. .model-warp.show{
  231. display: block;
  232. }
  233. .login-main{
  234. width: 100%;
  235. display: flex;
  236. flex-direction: column;
  237. align-items: center;
  238. height: 198rpx;
  239. padding: 170rpx 0 60rpx 0;
  240. .logo{
  241. width: 138rpx;
  242. height: 118rpx;
  243. display: block;
  244. }
  245. .logo-text{
  246. font-size: 30rpx;
  247. line-height: 44rpx;
  248. color: $color-system;
  249. font-weight: 600;
  250. margin-top: 20rpx;
  251. }
  252. }
  253. .login-input{
  254. width: 654rpx;
  255. height: 40rpx;
  256. padding: 24rpx;
  257. margin: 0 auto;
  258. margin-bottom: 20rpx;
  259. background: #F7F7F7;
  260. border-radius: 14rpx;
  261. position: relative;
  262. .input{
  263. width: 100%;
  264. height: 100%;
  265. background: #F7F7F7;
  266. font-size: $font-size-base;
  267. line-height: 40rpx;
  268. color: #333333;
  269. border-radius: 14rpx;
  270. }
  271. .iconfont{
  272. position: absolute;
  273. right: 0;
  274. top: 0;
  275. font-size: 46rpx;
  276. color: $color-system;
  277. font-weight: bold;
  278. z-index: 99;
  279. width: 96rpx;
  280. height: 96rpx;
  281. line-height: 96rpx;
  282. text-align: center;
  283. }
  284. &.link{
  285. background: #FFFFFF;
  286. margin-bottom: 40rpx;
  287. padding: 0 24rpx;
  288. line-height: 40rpx;
  289. font-size: $font-size-base;
  290. .login-reg{
  291. float: left;
  292. color: $color-system;
  293. }
  294. .login-pwd{
  295. float: right;
  296. color: $text-color;
  297. }
  298. }
  299. }
  300. .login-btn{
  301. width: 702rpx;
  302. height: 88rpx;
  303. border-radius: 14rpx;
  304. font-size: $font-size-base;
  305. line-height: 88rpx;
  306. color: #FFFFFF;
  307. margin: 0 auto;
  308. text-align: center;
  309. background: $btn-confirm;
  310. }
  311. .login-btn-last{
  312. width: 702rpx;
  313. font-size: $font-size-base;
  314. line-height: 160rpx;
  315. margin: 0 auto;
  316. color: $text-color;
  317. text-align: center;
  318. }
  319. .model-authorization{
  320. width: 100%;
  321. height: 100%;
  322. position: fixed;
  323. top: 0;
  324. left: 0;
  325. z-index: 999;
  326. .authorization{
  327. width: 518rpx;
  328. height: 320rpx;
  329. position: absolute;
  330. background: rgba(255,255,255,.7);
  331. left: 0;
  332. right: 0;
  333. bottom: 0;
  334. top: 0;
  335. margin: auto;
  336. .to-btn{
  337. position: absolute;
  338. top: 0;
  339. left: 0;
  340. right: 0;
  341. bottom: 0;
  342. margin: auto;
  343. width: 70%;
  344. height: 88rpx;
  345. font-size: $font-size-base;
  346. line-height: 88rpx;
  347. color: #FFFFFF;
  348. text-align: center;
  349. border-radius: 44rpx;
  350. }
  351. }
  352. }
  353. }
  354. </style>