login.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. },
  57. computed: {
  58. ...mapState(['isWxAuthorize'])
  59. },
  60. methods:{
  61. ...mapMutations(['login','logout']),
  62. async getWxAuthorize(){
  63. const wechatCode = await authorize.getCode('weixin');// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  64. const getUserInfo = await authorize.getUserInfo('weixin');
  65. this.UserService.UserLoginAuthApplets({
  66. code:wechatCode,
  67. encryptedData:getUserInfo.encryptedData,
  68. iv:getUserInfo.iv ,
  69. })
  70. .then(response =>{
  71. this.login(response.data);
  72. this.$store.commit('updateStatus',response.data)
  73. uni.setStorageSync('token',response.data.token)
  74. uni.setStorageSync('unionId',response.data.unionId)
  75. if(response.data.userIdentity === 1){
  76. setTimeout(()=>{
  77. this.$api.navigateTo('/seller/pages/index/index')
  78. },1500)
  79. }
  80. }).catch(error =>{
  81. this.logout()
  82. uni.setStorageSync('unionId',error.data.unionId)
  83. this.$store.commit('updateStatus',error.data)
  84. this.isSeller= true
  85. })
  86. },
  87. confirmLogin(){
  88. if( this.params.mobileOrEmail == ''){
  89. this.$util.msg('请输入账户名',2000)
  90. return
  91. }
  92. if( this.password == ''){
  93. this.$util.msg('请输入密码',2000)
  94. return
  95. }
  96. authorize.getSetting().then(res =>{
  97. console.log('用户是否授权过',res)
  98. if(res == 1){
  99. this.SellerLogin()
  100. }else{
  101. console.log(new Date +'用户未授权微信信息')
  102. this.$api.navigateTo('/pages/authorization/authorization?type=1')
  103. }
  104. })
  105. },
  106. SellerLogin(){
  107. this.SellerService.SellerLogin(this.params)
  108. .then(response =>{
  109. this.login(response.data);
  110. this.$store.commit('updateStatus',response.data)
  111. uni.setStorageSync('token',response.data.token)
  112. uni.setStorageSync('unionId',response.data.unionId)
  113. this.$api.navigateTo('/seller/pages/index/index')
  114. this.isSeller= false
  115. setTimeout(()=>{
  116. this.isSeller= true
  117. },1500)
  118. })
  119. .catch(error =>{
  120. this.$util.msg(error.msg,2000);
  121. })
  122. },
  123. storeUpdataeStatus(data){
  124. let user_key = {
  125. clubID:data.clubID,
  126. shopID:data.shopID,
  127. userID:data.userID,
  128. bindMobile:data.bindMobile,
  129. }
  130. uni.setStorageSync('token',data.token)
  131. this.$store.commit('updateStatus',user_key)
  132. this.login(data);
  133. },
  134. passwordClick() { //密码显隐操作
  135. this.isShowEye = !this.isShowEye;
  136. },
  137. },
  138. onShow() {
  139. authorize.getSetting().then(res =>{
  140. console.log('用户是否授权过',res)
  141. if(res == 1){
  142. this.getWxAuthorize()
  143. }else{
  144. console.log(new Date +'用户未授权微信信息')
  145. this.$api.navigateTo('/pages/authorization/authorization?type=1')
  146. }
  147. })
  148. }
  149. }
  150. </script>
  151. <style lang="scss">
  152. .login{
  153. width: 100%;
  154. height: auto;
  155. .model-warp.none{
  156. display: none;
  157. }
  158. .model-warp.show{
  159. display: block;
  160. }
  161. .login-main{
  162. width: 100%;
  163. display: flex;
  164. flex-direction: column;
  165. align-items: center;
  166. height: 198rpx;
  167. padding: 170rpx 0 60rpx 0;
  168. .logo{
  169. width: 138rpx;
  170. height: 118rpx;
  171. display: block;
  172. }
  173. .logo-text{
  174. font-size: 30rpx;
  175. line-height: 44rpx;
  176. color: $color-system;
  177. font-weight: 600;
  178. margin-top: 20rpx;
  179. }
  180. }
  181. .login-input{
  182. width: 600rpx;
  183. height: 40rpx;
  184. padding: 24rpx 0;
  185. margin: 0 auto;
  186. margin-bottom: 20rpx;
  187. background: #FFFFFF;
  188. position: relative;
  189. border-bottom: 1px solid #E1E1E1;
  190. .input{
  191. width: 100%;
  192. height: 100%;
  193. background: #FFFFFF;
  194. font-size: $font-size-28;
  195. line-height: 40rpx;
  196. color: #333333;
  197. }
  198. .iconfont{
  199. position: absolute;
  200. right: 0;
  201. top: 0;
  202. font-size: 44rpx;
  203. color: #999999;
  204. font-weight: bold;
  205. z-index: 99;
  206. width: 96rpx;
  207. height: 96rpx;
  208. line-height: 96rpx;
  209. text-align: center;
  210. }
  211. &.link{
  212. background: #FFFFFF;
  213. margin-bottom: 40rpx;
  214. padding: 0 24rpx;
  215. line-height: 40rpx;
  216. font-size: $font-size-28;
  217. .login-reg{
  218. float: left;
  219. color: $color-system;
  220. }
  221. .login-pwd{
  222. float: right;
  223. color: $text-color;
  224. }
  225. }
  226. }
  227. .login-btn{
  228. width: 600rpx;
  229. height: 88rpx;
  230. border-radius:44rpx;
  231. font-size: $font-size-28;
  232. line-height: 88rpx;
  233. color: #FFFFFF;
  234. margin: 0 auto;
  235. text-align: center;
  236. background: $btn-confirm;
  237. margin-top: 100rpx;
  238. }
  239. .login-tel{
  240. width: 702rpx;
  241. font-size: $font-size-28;
  242. line-height: 240rpx;
  243. margin: 0 auto;
  244. color: $text-color;
  245. text-align: center;
  246. margin-top: 100rpx;
  247. }
  248. }
  249. </style>