loginByCode.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. <template>
  2. <view style="padding: 16px;font-size: 14px;">
  3. <tn-nav-bar fixed alpha customBack>
  4. <view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
  5. <text class='icon tn-icon-left'></text>
  6. </view>
  7. </tn-nav-bar>
  8. <view style="text-align: center;padding: 80px 0">
  9. <image src="../../static/logo.png" style="width: 110px; height: 100px;"></image>
  10. <view style="margin: 8px 0;"><text style="font-size: 22px;font-weight: bold;" :style="{fontSize:(wxFontSize+5)+'px'}">速立保</text></view>
  11. </view>
  12. <uni-forms ref="baseForm" :modelValue="baseFormData" :label-width="wxFontSize+70">
  13. <uni-forms-item label="手机号" required :labelFontSize="wxFontSize-2">
  14. <uni-easyinput type="number" :inputSize="wxFontSize-3" :placeholder-style="styleString" v-model="baseFormData.userName" :clearable="false" placeholder="请输入手机号" />
  15. </uni-forms-item>
  16. <uni-forms-item label="验证码" required :labelFontSize="wxFontSize-2">
  17. <uni-easyinput v-model="baseFormData.code" :inputSize="wxFontSize-3" :placeholder-style="styleString" :clearable="false" placeholder="请输入验证码" >
  18. <template #right>
  19. <view @click="getCode" style="margin-right: 4px;background: #ddd;padding: 4px 10px;border-radius: 14px;" :style="{fontSize:(wxFontSize-3)+'px'}">{{seconds?seconds+'s后重新获取':'获取验证码'}}</view>
  20. </template>
  21. </uni-easyinput>
  22. </uni-forms-item>
  23. </uni-forms>
  24. <view :class="!agreeValue?'':'isHidden'" style="background: #00000088;
  25. display: inline;
  26. padding: 4px 10px;
  27. border-radius: 12px;
  28. border-bottom-left-radius: 0;
  29. color: #fff;font-size: 12px;margin-left: 12px;" :style="{fontSize:(wxFontSize-5)+'px'}">
  30. 请先阅读并同意协议
  31. </view>
  32. <view style="margin-top:4px">
  33. <tn-checkbox v-model="agreeValue" activeColor="#1d60b1" name="选项1" :size="wxFontSize+17">
  34. <text :style="{fontSize:(wxFontSize-2)+'px'}">阅读并同意</text>
  35. </tn-checkbox>
  36. <view style="display: inline;font-size: 15px;margin-left: -12px;vertical-align: middle;" @click="showInfo()" :style="{fontSize:(wxFontSize-2)+'px'}">
  37. <view style="color: #1d60b1;display: inline;">《用户服务协议》</view>
  38. <view style="display: inline;color: #1d60b1;" @click="showInfo2()">《隐私政策》</view>
  39. </view>
  40. </view>
  41. <view class="" hover-class="button-hover" style="margin-top: 24px;" v-if="agreeValue">
  42. <button :disabled="!canSave" style="border-radius: 50rpx;width: 100%;background-color: #1d60b1;" type="primary" @click="saveForm" :style="{fontSize:(wxFontSize-2)+'px'}">登录</button>
  43. </view>
  44. <view class="" hover-class="button-hover" style="margin-top: 24px;" v-if="!agreeValue">
  45. <button :disabled="!canSave" style="border-radius: 50rpx;width: 100%;background-color: #1d60b1;" type="primary" @click="showToast" :style="{fontSize:(wxFontSize-2)+'px'}">登录</button>
  46. </view>
  47. <view @click="showLogin" style="text-align: center;margin-top: 24px;" :style="{fontSize:(wxFontSize-4)+'px'}">手机号快捷登录</view>
  48. </view>
  49. </template>
  50. <script>
  51. import request from '../../utils/request';
  52. export default {
  53. data() {
  54. return {
  55. agreeValue: false,
  56. value: [],
  57. range: [{
  58. "value": 0,
  59. "text": ""
  60. }],
  61. baseFormData:{
  62. userName:'',
  63. code:''
  64. },
  65. lxSessionKey: '',
  66. openId: '',
  67. unionid: '',
  68. canSave:true,
  69. seconds:0,
  70. tryTime:0,
  71. wxFontSize: 17,
  72. styleString:'font-size:'+14+'px'
  73. }
  74. },
  75. onLoad() {
  76. const appBaseInfo = wx.getAppBaseInfo();
  77. this.wxFontSize = uni.getStorageSync('fontSize')||appBaseInfo.fontSizeSetting||17;
  78. this.styleString='font-size:'+(this.wxFontSize-3)+'px';
  79. },
  80. onShow(){
  81. if(uni.getStorageSync('agreeInfo')){
  82. this.agreeValue = true;
  83. }
  84. },
  85. beforeDestroy() {
  86. // 组件销毁前清除定时器
  87. this.clearTimer();
  88. },
  89. methods: {
  90. goBack() {
  91. const pages = getCurrentPages()
  92. // 有可返回的页面则直接返回,uni.navigateBack 默认返回失败之后会自动刷新页面 ,无法继续返回
  93. if (pages.length > 1) {
  94. uni.navigateBack()
  95. return;
  96. }else{
  97. uni.reLaunch({
  98. url: '/pages/index/index'
  99. })
  100. }
  101. },
  102. getCode(){
  103. if(!this.baseFormData.userName){
  104. uni.showToast({
  105. title: '请输入手机号',
  106. icon: 'none'
  107. })
  108. return false;
  109. }
  110. if(this.seconds>0){
  111. return false;
  112. }else{
  113. // if(!this.agreeValue){
  114. // uni.showToast({
  115. // title: '请先阅读并同意协议',
  116. // icon: 'none'
  117. // })
  118. // wx.vibrateShort();
  119. // return false;
  120. // }
  121. this.seconds = 60;
  122. this.getCodeByPhone();
  123. }
  124. },
  125. getCodeByPhone(){
  126. let params = {
  127. mobile: this.baseFormData.userName,
  128. platType: "slb",
  129. mpType: "engineer",
  130. smsType:'Login'
  131. }
  132. const that = this;
  133. request.post('/smsSend/sendSMS', {bean:JSON.stringify(params)}).then(res => {
  134. console.error(res);
  135. if (res&&res.success) {
  136. that.startCountdown();
  137. }else{
  138. uni.showToast({
  139. title: res.msg||'获取失败,请稍后再试',
  140. icon: 'none'
  141. })
  142. }
  143. })
  144. },
  145. startCountdown() {
  146. this.timer = setInterval(() => {
  147. if (this.seconds > 0) {
  148. this.seconds--;
  149. } else {
  150. // 倒计时结束,清除定时器
  151. this.clearTimer();
  152. // 执行倒计时结束后的操作
  153. }
  154. }, 1000);
  155. },
  156. // 清除定时器
  157. clearTimer() {
  158. clearInterval(this.timer);
  159. this.timer = null;
  160. },
  161. showToast() {
  162. uni.showToast({
  163. title: '请先阅读并同意协议',
  164. icon: 'none'
  165. })
  166. wx.vibrateShort();
  167. return false;
  168. },
  169. saveForm(){
  170. if(!this.baseFormData.userName){
  171. uni.showToast({
  172. title: '请输入手机号',
  173. icon: 'none'
  174. })
  175. return false;
  176. }
  177. if(!this.baseFormData.code){
  178. uni.showToast({
  179. title: '请输入验证码',
  180. icon: 'none'
  181. })
  182. return false;
  183. }
  184. let params = {
  185. userName:this.baseFormData.userName,
  186. smCode: this.baseFormData.code,
  187. mpType: "engineer",
  188. }
  189. const that = this;
  190. request.post('/slbSmLogin', params).then(res => {
  191. console.error(res);
  192. if (res&&res.success) {
  193. uni.showToast({
  194. title: '登录成功',
  195. icon: 'none'
  196. })
  197. uni.setStorageSync('loginStatus', 'true');
  198. uni.setStorageSync('userMap', JSON.stringify(res.resultMap));
  199. uni.setStorageSync('userNo', res.resultMap.accountName);
  200. uni.removeStorageSync('loginOut');
  201. that.getUserInfo();
  202. }else{
  203. uni.showToast({
  204. title: res.msg,
  205. icon: 'none'
  206. })
  207. }
  208. })
  209. },
  210. showInfo() {
  211. if(uni.getStorageSync('agreeInfo')){
  212. uni.navigateTo({
  213. url: '/pages/login/info?counted=1'
  214. })
  215. return false;
  216. }else{
  217. uni.navigateTo({
  218. url: '/pages/login/info'
  219. })
  220. }
  221. },
  222. showInfo2() {
  223. uni.navigateTo({
  224. url:'/pages/webview/web-view?url='+encodeURIComponent('https://slb-m.lx-device.com/webview?title=隐私协议&url='+'https://oss.lx-device.com/userFeedback/1735201139460G1J.docx'),
  225. })
  226. },
  227. showLogin(){
  228. uni.redirectTo({
  229. url:'/pages/login/login'
  230. })
  231. },
  232. loginAgain() {
  233. let that = this;
  234. uni.login({
  235. success(res) {
  236. that.loginByCode(res.code);
  237. },
  238. fail(res) {
  239. uni.hideLoading();
  240. }
  241. });
  242. },
  243. loginByCode(frontId) {
  244. const that = this;
  245. uni.setStorageSync('loginStatus', 'false');
  246. wx.getUserInfo({
  247. success: function(res) {
  248. console.error(res);
  249. request.post("/slbMpAutoLogin", {
  250. code: frontId,
  251. appType: 'ma',
  252. encryptedData: res.encryptedData,
  253. iv: res.iv
  254. }, {
  255. login: false,
  256. warn: false,
  257. loading: false
  258. }).then(res2 => {
  259. console.error(res2);
  260. if (res2.success) {
  261. //登录成功
  262. uni.setStorageSync('loginStatus', 'true');
  263. uni.setStorageSync('userMap', JSON.stringify(res2.resultMap));
  264. uni.setStorageSync('userNo', res2.resultMap.accountName);
  265. that.getUserInfo();
  266. } else {
  267. uni.showToast({
  268. title: res2.msg,
  269. icon: 'none'
  270. })
  271. that.canSave = true;
  272. //登录失败,
  273. }
  274. console.error(res2);
  275. });
  276. }
  277. })
  278. },
  279. getUserInfo() {
  280. let that = this;
  281. request.post('/slbWxma/getPersonlInfo', {
  282. }).then(res => {
  283. that.canSave = true;
  284. if (res&&res.success) {
  285. that.tryTime = 0;
  286. that.personInfo = res.resultMap.userInfo || {};
  287. uni.setStorageSync('userInfo', JSON.stringify(res.resultMap.userInfo));
  288. that.goBack();
  289. }else{
  290. that.tryTime++;
  291. if(that.tryTime<5){
  292. setTimeout(()=>{
  293. that.loginAgain()
  294. },500)
  295. }else{
  296. uni.showToast({
  297. title: '登录超时,请再试一次',
  298. icon: 'none'
  299. })
  300. }
  301. }
  302. // if (res.success) {
  303. // that.personInfo = res.resultMap.userInfo || {};
  304. // uni.setStorageSync('userInfo', JSON.stringify(res.resultMap.userInfo));
  305. // }
  306. // uni.navigateBack();
  307. // console.warn(res);
  308. })
  309. },
  310. }
  311. }
  312. </script>
  313. <style lang="scss" scoped>
  314. .isHidden {
  315. visibility: hidden;
  316. }
  317. .template-edit {}
  318. /* 胶囊*/
  319. .tn-custom-nav-bar__back {
  320. width: 60%;
  321. height: 100%;
  322. position: relative;
  323. display: flex;
  324. justify-content: space-evenly;
  325. align-items: center;
  326. box-sizing: border-box;
  327. // background-color: rgba(0, 0, 0, 0.15);
  328. border-radius: 1000rpx;
  329. border: 1rpx solid rgba(255, 255, 255, 0.5);
  330. // color: #FFFFFF;
  331. font-size: 18px;
  332. .icon {
  333. display: block;
  334. flex: 1;
  335. margin: auto;
  336. text-align: center;
  337. }
  338. &:before {
  339. content: " ";
  340. width: 1rpx;
  341. height: 110%;
  342. position: absolute;
  343. top: 22.5%;
  344. left: 0;
  345. right: 0;
  346. margin: auto;
  347. transform: scale(0.5);
  348. transform-origin: 0 0;
  349. pointer-events: none;
  350. box-sizing: border-box;
  351. opacity: 0.7;
  352. background-color: #FFFFFF;
  353. }
  354. }
  355. /* 底部悬浮按钮 start*/
  356. .tn-tabbar-height {
  357. min-height: 100rpx;
  358. height: calc(120rpx + env(safe-area-inset-bottom) / 2);
  359. }
  360. .tn-footerfixed {
  361. position: fixed;
  362. width: 100%;
  363. bottom: calc(30rpx + env(safe-area-inset-bottom));
  364. z-index: 1024;
  365. box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0);
  366. }
  367. /* 底部悬浮按钮 end*/
  368. </style>