dt_login.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <FootDialog direction="center" :config="config" :isTitle="false" :isRadius="false" :visible.sync="dialogShow" @close="$emit('close')">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <template slot="main">
  5. <view class="dt-login-wrap">
  6. <view class="title">您还没登录</view>
  7. <view class="subtitle">请先登录再进行操作</view>
  8. <image class="login-icon" src="/static/common/login.png" ></image>
  9. <view class="btn-wrap">
  10. <button class="btn-base"
  11. hover-class="button-hover"
  12. @tap="hide">暂不登录</button>
  13. <button class=" btn-base "
  14. style="color: #2f7ff5;"
  15. hover-class="button-hover"
  16. open-type="getPhoneNumber"
  17. @getphonenumber="tapGetPhoneNumber">立即登录</button>
  18. </view>
  19. </view>
  20. </template>
  21. <!-- #endif -->
  22. <!-- #ifdef APP-PLUS -->
  23. <template slot="main">
  24. <view class="dt-login-wrap">
  25. <view class="title">登 录</view>
  26. <view>
  27. <view>
  28. <text>账号:</text>
  29. <input v-model="formData.account" type="number" placeholder="请输入账号"/>
  30. </view>
  31. <view class="line"></view>
  32. <view>
  33. <text>密码:</text>
  34. <input v-model="formData.passwd" placeholder="请输入密码" />
  35. </view>
  36. </view>
  37. <view class="btn-wrap">
  38. <button class="btn-base dt-color-primary"
  39. hover-class="button-hover"
  40. @tap="touristLogin">登 录</button>
  41. </view>
  42. </view>
  43. </template>
  44. <!-- #endif -->
  45. </FootDialog>
  46. </template>
  47. <script>
  48. import FootDialog from './foot_dialog.vue'
  49. import { setTimeout } from 'timers';
  50. export default {
  51. components: {
  52. FootDialog
  53. },
  54. data () {
  55. return {
  56. config: {
  57. mainBgColor: 'transparent'
  58. },
  59. dialogShow: false,
  60. respWx:{},
  61. respWx2:{},
  62. respLogin:{},
  63. timer:null,
  64. inviteCode:null,
  65. formData:{
  66. account:'',
  67. passwd:''
  68. },
  69. formRules:{
  70. account:[{
  71. required:true,
  72. message:'请输入账号'
  73. },{
  74. type:'mobile',
  75. message:'手机号码有误!'
  76. }],
  77. passwd:[{
  78. required:true,
  79. message:'请输入密码'
  80. }]
  81. }
  82. }
  83. },
  84. methods: {
  85. show () {
  86. console.log("show");
  87. let that=this
  88. this.inviteCode = this.$auth.getInviteCode()
  89. console.log("inviteCode",this.inviteCode);
  90. this.dialogShow=true;
  91. this.$mpi.wxLogin().then(res => {
  92. this.respWx = res
  93. console.log("res",res);
  94. })
  95. this.setTimer()
  96. },
  97. hide () {
  98. console.log("hide");
  99. if(this.timer){
  100. clearTimeout(this.timer)
  101. this.timer = null
  102. console.log('clearTimeout')
  103. }
  104. this.dialogShow=false;
  105. },
  106. async setTimer(){
  107. console.log("setTimer");
  108. this.respWx = await this.$mpi.wxLogin()
  109. this.timer = setTimeout(()=>{
  110. this.setTimer()
  111. },240000) // 每隔4分钟重新请求 jscode
  112. },
  113. async login(detail){
  114. console.log("2:login",detail);
  115. try{
  116. this.$dialog.showLoading()
  117. if(!this.respLogin.sessionKey){
  118. this.respLogin = await this.$api.loginByCode({
  119. _isReject:true,
  120. code:this.respWx.code
  121. })
  122. }
  123. console.log(this.respLogin);
  124. let resp = await this.$api.loginByWxapp({
  125. _isReject:true,
  126. openId: this.respLogin.openId,
  127. sessionKey: this.respLogin.sessionKey,
  128. encryptedData: detail.encryptedData,
  129. iv: detail.iv,
  130. inviteCode: this.inviteCode
  131. })
  132. console.log(56,resp)
  133. resp.openId = this.respLogin.openId
  134. resp.sessionKey = this.respLogin.sessionKey
  135. let userType = this.$global.userType.member
  136. this.$auth.login(userType, resp.sessionId, resp.userId, resp)
  137. this.hide()
  138. // this.$auth.setInviteCode(null);
  139. this.$auth.removeInviteCode();
  140. let a = this.$auth.getInviteCode();
  141. if(this.inviteCode){
  142. this.$emit('getDistributorCoupon')
  143. }else{
  144. this.$emit('signIn', resp)
  145. }
  146. }catch(err){
  147. // console.log(72,err)
  148. this.$dialog.alert({
  149. content: err.errmsg || '服务繁忙~'
  150. })
  151. }finally{
  152. this.$dialog.hideLoading()
  153. if(this.timer){
  154. clearTimeout(this.timer)
  155. this.setTimer()
  156. }
  157. }
  158. },
  159. /**
  160. * app 登陆逻辑
  161. */
  162. async touristLogin() {
  163. console.log("");
  164. if(!this.validate(this.formRules,this.formData)){
  165. return
  166. }
  167. try{
  168. this.$dialog.showLoading()
  169. if(!this.respLogin.sessionKey){
  170. this.respLogin = await this.$api.loginByCode({
  171. _isReject:true,
  172. code:this.respWx.code
  173. })
  174. }
  175. let resp = await this.$api.touristLogin({
  176. account:this.formData.account,
  177. passwd:this.formData.passwd
  178. })
  179. console.log(resp)
  180. let userType = this.$global.userType.member
  181. resp.openId = this.respLogin.openId
  182. resp.sessionKey = this.respLogin.sessionKey
  183. this.$auth.login(userType, resp.sessionId, resp.userId, resp)
  184. this.hide()
  185. this.$auth.removeInviteCode();
  186. let a = this.$auth.getInviteCode();
  187. if(this.inviteCode){
  188. this.$emit('getDistributorCoupon')
  189. }else{
  190. this.$emit('signIn', resp)
  191. }
  192. }catch(err){
  193. // console.log(72,err)
  194. this.$dialog.alert({
  195. content: err.errmsg || '服务繁忙~'
  196. })
  197. }finally{
  198. this.$dialog.hideLoading()
  199. if(this.timer){
  200. clearTimeout(this.timer)
  201. this.setTimer()
  202. }
  203. }
  204. },
  205. /**1 :点击登陆
  206. * @param {Object} e
  207. */
  208. async tapGetPhoneNumber (e) {
  209. console.log(1,"点击登陆")
  210. // console.log(48,e.detail)
  211. if(e.detail.errMsg != 'getPhoneNumber:ok') {
  212. return
  213. }
  214. // let authSetting = await this.$mpi.wxGetSetting()
  215. // if(authSetting['scope.userInfo']) {
  216. // let userInfo = await this.$mpi.wxGetUserInfo()
  217. // console.log(56,userInfo)
  218. // }
  219. // console.log(55,authSetting)
  220. this.login(e.detail)
  221. },
  222. },
  223. beforeDestroy() {
  224. if(this.timer){
  225. clearTimeout(this.timer)
  226. this.timer = null
  227. console.log('clearTimeout')
  228. }
  229. }
  230. }
  231. </script>
  232. <style lang="scss">
  233. button{
  234. font-size: 28rpx;
  235. }
  236. .dt-login-wrap {
  237. margin: 0 auto;
  238. display: flex;
  239. flex-direction: column;
  240. align-items: center;
  241. width: 560upx;
  242. background-color: #fff;
  243. border-radius: 16upx;
  244. .title {
  245. padding-top:60upx;
  246. padding-bottom:28upx;
  247. font-size: 32upx;
  248. font-weight: bold;
  249. }
  250. .subtitle {
  251. color: #7e7e7e;
  252. font-size: 26upx;
  253. }
  254. .login-icon {
  255. margin: 25upx auto 52upx;
  256. width: 320upx;
  257. height: 340upx;
  258. }
  259. .btn-wrap {
  260. display: flex;
  261. width: 100%;
  262. line-height: 80upx;
  263. padding:8rpx 0rpx;
  264. font-size: 24rpx;
  265. border-top:1upx solid #f2f2f2;
  266. .btn-base {
  267. padding: 0 60rpx;
  268. flex: 1;
  269. text-align: center;
  270. color:#66656a;
  271. border-radius:0;
  272. }
  273. .btn-base:before {
  274. position: absolute;
  275. top: 0;
  276. right: 1upx;
  277. width: 100%;
  278. height: 100%;
  279. border-right:1upx solid #ebebeb;
  280. content: "";
  281. }
  282. .btn-base:last-child:before {
  283. display: none;
  284. content: "";
  285. }
  286. }
  287. }
  288. </style>