loginByCode.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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. // uni.navigateTo({
  217. // url:'/pages/webview/web-view?url='+'https://test-oss.lx-device.com/userFeedback/1732866523422nfH.docx',
  218. // })
  219. },
  220. showInfo2() {
  221. uni.navigateTo({
  222. url:'/pages/webview/web-view?url='+encodeURIComponent('https://slb-m.lx-device.com/webview?title=隐私协议&url='+'https://oss.lx-device.com/userFeedback/1734512475403YCv.docx'),
  223. })
  224. },
  225. showLogin(){
  226. uni.redirectTo({
  227. url:'/pages/login/login'
  228. })
  229. },
  230. loginAgain() {
  231. let that = this;
  232. uni.login({
  233. success(res) {
  234. that.loginByCode(res.code);
  235. },
  236. fail(res) {
  237. uni.hideLoading();
  238. }
  239. });
  240. },
  241. loginByCode(frontId) {
  242. const that = this;
  243. uni.setStorageSync('loginStatus', 'false');
  244. wx.getUserInfo({
  245. success: function(res) {
  246. console.error(res);
  247. request.post("/slbMpAutoLogin", {
  248. code: frontId,
  249. appType: 'ma',
  250. encryptedData: res.encryptedData,
  251. iv: res.iv
  252. }, {
  253. login: false,
  254. warn: false,
  255. loading: false
  256. }).then(res2 => {
  257. console.error(res2);
  258. if (res2.success) {
  259. //登录成功
  260. uni.setStorageSync('loginStatus', 'true');
  261. uni.setStorageSync('userMap', JSON.stringify(res2.resultMap));
  262. uni.setStorageSync('userNo', res2.resultMap.accountName);
  263. that.getUserInfo();
  264. } else {
  265. uni.showToast({
  266. title: res2.msg,
  267. icon: 'none'
  268. })
  269. that.canSave = true;
  270. //登录失败,
  271. }
  272. console.error(res2);
  273. });
  274. }
  275. })
  276. },
  277. getUserInfo() {
  278. let that = this;
  279. request.post('/slbWxma/getPersonlInfo', {
  280. }).then(res => {
  281. that.canSave = true;
  282. if (res&&res.success) {
  283. that.tryTime = 0;
  284. that.personInfo = res.resultMap.userInfo || {};
  285. uni.setStorageSync('userInfo', JSON.stringify(res.resultMap.userInfo));
  286. that.goBack();
  287. }else{
  288. that.tryTime++;
  289. if(that.tryTime<5){
  290. setTimeout(()=>{
  291. that.loginAgain()
  292. },500)
  293. }else{
  294. uni.showToast({
  295. title: '登录超时,请再试一次',
  296. icon: 'none'
  297. })
  298. }
  299. }
  300. // if (res.success) {
  301. // that.personInfo = res.resultMap.userInfo || {};
  302. // uni.setStorageSync('userInfo', JSON.stringify(res.resultMap.userInfo));
  303. // }
  304. // uni.navigateBack();
  305. // console.warn(res);
  306. })
  307. },
  308. }
  309. }
  310. </script>
  311. <style lang="scss" scoped>
  312. .isHidden {
  313. visibility: hidden;
  314. }
  315. .template-edit {}
  316. /* 胶囊*/
  317. .tn-custom-nav-bar__back {
  318. width: 60%;
  319. height: 100%;
  320. position: relative;
  321. display: flex;
  322. justify-content: space-evenly;
  323. align-items: center;
  324. box-sizing: border-box;
  325. // background-color: rgba(0, 0, 0, 0.15);
  326. border-radius: 1000rpx;
  327. border: 1rpx solid rgba(255, 255, 255, 0.5);
  328. // color: #FFFFFF;
  329. font-size: 18px;
  330. .icon {
  331. display: block;
  332. flex: 1;
  333. margin: auto;
  334. text-align: center;
  335. }
  336. &:before {
  337. content: " ";
  338. width: 1rpx;
  339. height: 110%;
  340. position: absolute;
  341. top: 22.5%;
  342. left: 0;
  343. right: 0;
  344. margin: auto;
  345. transform: scale(0.5);
  346. transform-origin: 0 0;
  347. pointer-events: none;
  348. box-sizing: border-box;
  349. opacity: 0.7;
  350. background-color: #FFFFFF;
  351. }
  352. }
  353. /* 底部悬浮按钮 start*/
  354. .tn-tabbar-height {
  355. min-height: 100rpx;
  356. height: calc(120rpx + env(safe-area-inset-bottom) / 2);
  357. }
  358. .tn-footerfixed {
  359. position: fixed;
  360. width: 100%;
  361. bottom: calc(30rpx + env(safe-area-inset-bottom));
  362. z-index: 1024;
  363. box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0);
  364. }
  365. /* 底部悬浮按钮 end*/
  366. </style>