login.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <view class="container login" :style="{paddingTop:CustomBar+'px'}" v-if="isSeller">
  3. <cu-custom :navbar-data='nvabarData' @navigateBack="hanldNavigateBack"></cu-custom>
  4. <view class="login-main">
  5. <image class="logo" src="https://static.caimei365.com/app/img/icon/login-logo@3x.png" mode=""></image>
  6. <text class="logo-text">生美/医美采购服务平台</text>
  7. </view>
  8. <view class="login-form">
  9. <view class="login-input">
  10. <input type="number" v-model="params.mobileOrEmail" maxlength="11" class="input" placeholder="请输入手机号"/>
  11. </view>
  12. <view class="login-input">
  13. <input v-show="isShowEye" type="text" v-model="params.password" maxlength="18" class="input" placeholder="请输入密码" autocomplete="new-password"/>
  14. <input v-show="!isShowEye" type="password" v-model="params.password" :password="true" maxlength="18" class="input" placeholder="请输入密码" autocomplete="new-password"/>
  15. <view class="iconfont" :class="isShowEye ? iconEyen : iconEyes" @click="passwordClick"></view>
  16. </view>
  17. </view>
  18. <view class="login-btn" @click="confirmLogin">协销登录</view>
  19. <!-- 微信用户已绑定供应商账户 -->
  20. <error-alert v-if="iseErrorAlert"></error-alert>
  21. </view>
  22. </template>
  23. <script>
  24. import { mapState,mapMutations } from 'vuex';
  25. import errorAlert from '@/components/cm-module/modelAlert/errorAlert.vue'
  26. import authorize from '@/common/config/authorize.js'
  27. var self;
  28. export default{
  29. components:{
  30. errorAlert
  31. },
  32. data() {
  33. return{
  34. nvabarData: { //顶部自定义导航
  35. showCapsule: 0, // 是否显示左上角图标 1表示显示 0表示不显示,
  36. showSearch: 0,
  37. title: '登录', // 导航栏 中间的标题
  38. haveBack:false,
  39. textLeft:this.$store.state.isIphone
  40. },
  41. isIphoneX:this.$store.state.isIphoneX,
  42. CustomBar:this.CustomBar,// 顶部导航栏高度
  43. isShowEye:false,
  44. isSeller:true,
  45. iseErrorAlert:false,
  46. iconEyes:'icon-yanjing_yincang_o',
  47. iconEyen:'icon-yanjing_xianshi_o',
  48. params:{
  49. mobileOrEmail:'',//协销用户登录账号
  50. password:'',//协销登录密码
  51. unionId:uni.getStorageSync('unionId')
  52. }
  53. }
  54. },
  55. onLoad() {
  56. authorize.getSetting().then(wxResponse =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  57. if(wxResponse == 1){
  58. this.getWxAuthorize()
  59. }else{
  60. this.$api.navigateTo('/pages/authorization/authorization')
  61. this.isSeller= true
  62. }
  63. })
  64. },
  65. computed: {
  66. ...mapState(['isWxAuthorize'])
  67. },
  68. methods:{
  69. ...mapMutations(['login','logout']),
  70. async getWxAuthorize(){
  71. const wechatCode = await authorize.getCode('weixin');// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  72. const getUserInfo = await authorize.getUserInfo('weixin');
  73. this.UserService.UserLoginAuthApplets({
  74. code:wechatCode,
  75. encryptedData:getUserInfo.encryptedData,
  76. iv:getUserInfo.iv ,
  77. })
  78. .then(response =>{
  79. this.login(response.data);
  80. this.$store.commit('updateStatus',response.data)
  81. uni.setStorageSync('token',response.data.token)
  82. uni.setStorageSync('unionId',response.data.unionId)
  83. if(response.data.userIdentity === 1){
  84. setTimeout(()=>{
  85. this.$api.navigateTo('/seller/pages/index/index')
  86. },1500)
  87. }
  88. }).catch(error =>{
  89. this.logout()
  90. uni.setStorageSync('unionId',error.data.unionId)
  91. this.$store.commit('updateStatus',error.data)
  92. this.isSeller= true
  93. })
  94. },
  95. confirmLogin(){
  96. if( this.params.mobileOrEmail == ''){
  97. this.$util.msg('请输入账户名',2000)
  98. return
  99. }
  100. if( this.password == ''){
  101. this.$util.msg('请输入密码',2000)
  102. return
  103. }
  104. authorize.getSetting().then(wxResponse =>{// console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  105. if(wxResponse == 1){
  106. this.SellerLogin()
  107. }else{
  108. this.$api.navigateTo('/pages/authorization/authorization?type=1')
  109. }
  110. })
  111. },
  112. SellerLogin(){
  113. this.SellerService.SellerLogin(this.params)
  114. .then(response =>{
  115. this.login(response.data);
  116. this.$store.commit('updateStatus',response.data)
  117. uni.setStorageSync('token',response.data.token)
  118. uni.setStorageSync('unionId',response.data.unionId)
  119. this.$api.navigateTo('/seller/pages/index/index')
  120. this.isSeller= false
  121. setTimeout(()=>{
  122. this.isSeller= true
  123. },1500)
  124. })
  125. .catch(error =>{
  126. this.$util.msg(error.msg,2000);
  127. })
  128. },
  129. storeUpdataeStatus(data){
  130. let user_key = {
  131. clubID:data.clubID,
  132. shopID:data.shopID,
  133. userID:data.userID,
  134. bindMobile:data.bindMobile,
  135. }
  136. uni.setStorageSync('token',data.token)
  137. this.$store.commit('updateStatus',user_key)
  138. this.login(data);
  139. },
  140. passwordClick() { //密码显隐操作
  141. this.isShowEye = !this.isShowEye;
  142. },
  143. },
  144. onShow() {
  145. }
  146. }
  147. </script>
  148. <style lang="scss">
  149. .login{
  150. width: 100%;
  151. height: auto;
  152. .model-warp.none{
  153. display: none;
  154. }
  155. .model-warp.show{
  156. display: block;
  157. }
  158. .login-main{
  159. width: 100%;
  160. display: flex;
  161. flex-direction: column;
  162. align-items: center;
  163. height: 198rpx;
  164. padding: 170rpx 0 60rpx 0;
  165. .logo{
  166. width: 138rpx;
  167. height: 118rpx;
  168. display: block;
  169. }
  170. .logo-text{
  171. font-size: 30rpx;
  172. line-height: 44rpx;
  173. color: $color-system;
  174. font-weight: 600;
  175. margin-top: 20rpx;
  176. }
  177. }
  178. .login-input{
  179. width: 600rpx;
  180. height: 40rpx;
  181. padding: 24rpx 0;
  182. margin: 0 auto;
  183. margin-bottom: 20rpx;
  184. background: #FFFFFF;
  185. position: relative;
  186. border-bottom: 1px solid #E1E1E1;
  187. .input{
  188. width: 100%;
  189. height: 100%;
  190. background: #FFFFFF;
  191. font-size: $font-size-28;
  192. line-height: 40rpx;
  193. color: #333333;
  194. }
  195. .iconfont{
  196. position: absolute;
  197. right: 0;
  198. top: 0;
  199. font-size: 44rpx;
  200. color: #999999;
  201. font-weight: bold;
  202. z-index: 99;
  203. width: 96rpx;
  204. height: 96rpx;
  205. line-height: 96rpx;
  206. text-align: center;
  207. }
  208. &.link{
  209. background: #FFFFFF;
  210. margin-bottom: 40rpx;
  211. padding: 0 24rpx;
  212. line-height: 40rpx;
  213. font-size: $font-size-28;
  214. .login-reg{
  215. float: left;
  216. color: $color-system;
  217. }
  218. .login-pwd{
  219. float: right;
  220. color: $text-color;
  221. }
  222. }
  223. }
  224. .login-btn{
  225. width: 600rpx;
  226. height: 88rpx;
  227. border-radius:44rpx;
  228. font-size: $font-size-28;
  229. line-height: 88rpx;
  230. color: #FFFFFF;
  231. margin: 0 auto;
  232. text-align: center;
  233. background: $btn-confirm;
  234. margin-top: 100rpx;
  235. }
  236. .login-tel{
  237. width: 702rpx;
  238. font-size: $font-size-28;
  239. line-height: 240rpx;
  240. margin: 0 auto;
  241. color: $text-color;
  242. text-align: center;
  243. margin-top: 100rpx;
  244. }
  245. }
  246. </style>