loginByCode.vue 9.4 KB

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