login-accont.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. changePasswordType(e){
  221. if(this.inputType ==='password'){
  222. this.inputType = 'text'
  223. this.passIconType = 'icon-yanjing_xianshi_o'
  224. }else{
  225. this.inputType = 'password'
  226. this.passIconType = 'icon-yanjing_yincang_o'
  227. }
  228. }
  229. }
  230. }
  231. </script>
  232. <style lang="scss">
  233. .login{
  234. width: 100%;
  235. height: auto;
  236. .model-warp.none{
  237. display: none;
  238. }
  239. .model-warp.show{
  240. display: block;
  241. }
  242. .login-main{
  243. width: 100%;
  244. display: flex;
  245. flex-direction: column;
  246. align-items: center;
  247. height: 198rpx;
  248. padding: 170rpx 0 60rpx 0;
  249. .logo{
  250. width: 138rpx;
  251. height: 118rpx;
  252. display: block;
  253. }
  254. .logo-text{
  255. font-size: 30rpx;
  256. line-height: 44rpx;
  257. color: $color-system;
  258. font-weight: 600;
  259. margin-top: 20rpx;
  260. }
  261. }
  262. .login-input{
  263. width: 654rpx;
  264. height: 40rpx;
  265. padding: 24rpx;
  266. margin: 0 auto;
  267. margin-bottom: 20rpx;
  268. background: #F7F7F7;
  269. border-radius: 14rpx;
  270. position: relative;
  271. .input{
  272. width: 100%;
  273. height: 100%;
  274. background: #F7F7F7;
  275. font-size: $font-size-base;
  276. line-height: 40rpx;
  277. color: #333333;
  278. border-radius: 14rpx;
  279. }
  280. .iconfont{
  281. position: absolute;
  282. right: 0;
  283. top: 0;
  284. font-size: 46rpx;
  285. color: $color-system;
  286. font-weight: bold;
  287. z-index: 99;
  288. width: 96rpx;
  289. height: 96rpx;
  290. line-height: 96rpx;
  291. text-align: center;
  292. }
  293. &.link{
  294. background: #FFFFFF;
  295. margin-bottom: 40rpx;
  296. padding: 0 24rpx;
  297. line-height: 40rpx;
  298. font-size: $font-size-base;
  299. .login-reg{
  300. float: left;
  301. color: $color-system;
  302. }
  303. .login-pwd{
  304. float: right;
  305. color: $text-color;
  306. }
  307. }
  308. }
  309. .login-btn{
  310. width: 702rpx;
  311. height: 88rpx;
  312. border-radius: 14rpx;
  313. font-size: $font-size-base;
  314. line-height: 88rpx;
  315. color: #FFFFFF;
  316. margin: 0 auto;
  317. text-align: center;
  318. background: $btn-confirm;
  319. }
  320. .login-btn-last{
  321. width: 702rpx;
  322. font-size: $font-size-base;
  323. line-height: 160rpx;
  324. margin: 0 auto;
  325. color: $text-color;
  326. text-align: center;
  327. }
  328. .model-authorization{
  329. width: 100%;
  330. height: 100%;
  331. position: fixed;
  332. top: 0;
  333. left: 0;
  334. z-index: 999;
  335. .authorization{
  336. width: 518rpx;
  337. height: 320rpx;
  338. position: absolute;
  339. background: rgba(255,255,255,.7);
  340. left: 0;
  341. right: 0;
  342. bottom: 0;
  343. top: 0;
  344. margin: auto;
  345. .to-btn{
  346. position: absolute;
  347. top: 0;
  348. left: 0;
  349. right: 0;
  350. bottom: 0;
  351. margin: auto;
  352. width: 70%;
  353. height: 88rpx;
  354. font-size: $font-size-base;
  355. line-height: 88rpx;
  356. color: #FFFFFF;
  357. text-align: center;
  358. border-radius: 44rpx;
  359. }
  360. }
  361. }
  362. }
  363. </style>