login-accont.vue 9.2 KB

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