dt_login.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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.$util.refreshPage(['/pagesM/pages/category','/pagesM/pages/shop_car'])
  139. // this.$auth.setInviteCode(null);
  140. this.$auth.removeInviteCode();
  141. let a = this.$auth.getInviteCode();
  142. if(this.inviteCode){
  143. this.$emit('getDistributorCoupon')
  144. }else{
  145. this.$emit('signIn', resp)
  146. }
  147. }catch(err){
  148. // console.log(72,err)
  149. this.$dialog.alert({
  150. content: err.errmsg || '服务繁忙~'
  151. })
  152. }finally{
  153. this.$dialog.hideLoading()
  154. if(this.timer){
  155. clearTimeout(this.timer)
  156. this.setTimer()
  157. }
  158. }
  159. },
  160. /**
  161. * app 登陆逻辑
  162. */
  163. async touristLogin() {
  164. console.log("");
  165. if(!this.validate(this.formRules,this.formData)){
  166. return
  167. }
  168. try{
  169. this.$dialog.showLoading()
  170. if(!this.respLogin.sessionKey){
  171. this.respLogin = await this.$api.loginByCode({
  172. _isReject:true,
  173. code:this.respWx.code
  174. })
  175. }
  176. let resp = await this.$api.touristLogin({
  177. account:this.formData.account,
  178. passwd:this.formData.passwd
  179. })
  180. console.log(resp)
  181. let userType = this.$global.userType.member
  182. resp.openId = this.respLogin.openId
  183. resp.sessionKey = this.respLogin.sessionKey
  184. this.$auth.login(userType, resp.sessionId, resp.userId, resp)
  185. this.hide()
  186. this.$util.refreshPage(['pages/index','pages/category','pages/shop_car'])
  187. this.$auth.removeInviteCode();
  188. let a = this.$auth.getInviteCode();
  189. if(this.inviteCode){
  190. this.$emit('getDistributorCoupon')
  191. }else{
  192. this.$emit('signIn', resp)
  193. }
  194. }catch(err){
  195. // console.log(72,err)
  196. this.$dialog.alert({
  197. content: err.errmsg || '服务繁忙~'
  198. })
  199. }finally{
  200. this.$dialog.hideLoading()
  201. if(this.timer){
  202. clearTimeout(this.timer)
  203. this.setTimer()
  204. }
  205. }
  206. },
  207. /**1 :点击登陆
  208. * @param {Object} e
  209. */
  210. async tapGetPhoneNumber (e) {
  211. console.log(1,"点击登陆")
  212. // console.log(48,e.detail)
  213. if(e.detail.errMsg != 'getPhoneNumber:ok') {
  214. return
  215. }
  216. // let authSetting = await this.$mpi.wxGetSetting()
  217. // if(authSetting['scope.userInfo']) {
  218. // let userInfo = await this.$mpi.wxGetUserInfo()
  219. // console.log(56,userInfo)
  220. // }
  221. // console.log(55,authSetting)
  222. this.login(e.detail)
  223. },
  224. },
  225. beforeDestroy() {
  226. if(this.timer){
  227. clearTimeout(this.timer)
  228. this.timer = null
  229. console.log('clearTimeout')
  230. }
  231. }
  232. }
  233. </script>
  234. <style lang="scss">
  235. button{
  236. font-size: 28rpx;
  237. }
  238. .dt-login-wrap {
  239. margin: 0 auto;
  240. display: flex;
  241. flex-direction: column;
  242. align-items: center;
  243. width: 560upx;
  244. background-color: #fff;
  245. border-radius: 16upx;
  246. .title {
  247. padding-top:60upx;
  248. padding-bottom:28upx;
  249. font-size: 32upx;
  250. font-weight: bold;
  251. }
  252. .subtitle {
  253. color: #7e7e7e;
  254. font-size: 26upx;
  255. }
  256. .login-icon {
  257. margin: 25upx auto 52upx;
  258. width: 320upx;
  259. height: 340upx;
  260. }
  261. .btn-wrap {
  262. display: flex;
  263. width: 100%;
  264. line-height: 80upx;
  265. padding:8rpx 0rpx;
  266. font-size: 24rpx;
  267. border-top:1upx solid #f2f2f2;
  268. .btn-base {
  269. padding: 0 60rpx;
  270. flex: 1;
  271. text-align: center;
  272. color:#66656a;
  273. border-radius:0;
  274. }
  275. .btn-base:before {
  276. position: absolute;
  277. top: 0;
  278. right: 1upx;
  279. width: 100%;
  280. height: 100%;
  281. border-right:1upx solid #ebebeb;
  282. content: "";
  283. }
  284. .btn-base:last-child:before {
  285. display: none;
  286. content: "";
  287. }
  288. }
  289. }
  290. </style>