login.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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. <view :class="!agreeValue?'':'isHidden'" style="background: #00000088;
  13. display: inline;
  14. padding: 4px 10px;
  15. border-radius: 12px;
  16. border-bottom-left-radius: 0;
  17. color: #fff;font-size: 12px;margin-left: 12px;">
  18. 请先阅读并同意协议
  19. </view>
  20. <view style="margin-top:4px">
  21. <tn-checkbox v-model="agreeValue" activeColor="#1d60b1" name="选项1">
  22. 阅读并同意
  23. </tn-checkbox>
  24. <view style="display: inline;font-size: 15px;" @click="showInfo()">
  25. <view style="color: #1d60b1;display: inline;">《用户服务协议》</view>
  26. <view style="display: inline;color: #1d60b1;" @click="showInfo2()">《隐私政策》</view>
  27. </view>
  28. </view>
  29. <view class="" hover-class="button-hover" style="margin-top: 24px;" v-if="agreeValue">
  30. <button :disabled="!canSave" style="border-radius: 50rpx;width: 100%;background-color: #1d60b1;" type="primary" open-type="getPhoneNumber"
  31. @getphonenumber="getPhoneNumber">手机号快捷登录</button>
  32. </view>
  33. <view class="" hover-class="button-hover" style="margin-top: 24px;" v-if="!agreeValue">
  34. <button :disabled="!canSave" style="border-radius: 50rpx;width: 100%;background-color: #1d60b1;" type="primary" @click="showToast">手机号快捷登录</button>
  35. </view>
  36. <view @click="showLogin" style="text-align: center;margin-top: 24px;">验证码登录</view>
  37. </view>
  38. </template>
  39. <script>
  40. import request from '../../utils/request';
  41. export default {
  42. data() {
  43. return {
  44. agreeValue: false,
  45. value: [],
  46. range: [{
  47. "value": 0,
  48. "text": ""
  49. }],
  50. lxSessionKey: '',
  51. openId: '',
  52. unionid: '',
  53. canSave:true,
  54. }
  55. },
  56. onLoad() {
  57. // this.getLxSessionKey()
  58. },
  59. onShow(){
  60. if(uni.getStorageSync('agreeInfo')){
  61. this.agreeValue = true;
  62. }
  63. },
  64. beforeDestroy(){
  65. uni.removeStorageSync('agreeInfo')
  66. },
  67. methods: {
  68. goBack() {
  69. uni.navigateBack();
  70. },
  71. showToast() {
  72. uni.showToast({
  73. title: '请先阅读并同意协议',
  74. icon: 'none'
  75. })
  76. wx.vibrateShort();
  77. },
  78. showInfo() {
  79. if(uni.getStorageSync('agreeInfo')){
  80. uni.navigateTo({
  81. url: '/pages/login/info?counted=1'
  82. })
  83. return false;
  84. }else{
  85. uni.navigateTo({
  86. url: '/pages/login/info'
  87. })
  88. }
  89. // uni.navigateTo({
  90. // url:'/pages/webview/web-view?url='+'https://test-oss.lx-device.com/userFeedback/1732866523422nfH.docx',
  91. // })
  92. },
  93. showInfo2() {
  94. uni.navigateTo({
  95. url:'/pages/webview/web-view?url='+encodeURIComponent('http://slb-m.dev.ml1993.com/webview?title=隐私协议&url='+'https://test-oss.lx-device.com/userFeedback/1734308677563sj9.docx'),
  96. })
  97. },
  98. showLogin(){
  99. uni.redirectTo({
  100. url:'/pages/login/loginByCode'
  101. })
  102. },
  103. change(e) {
  104. this.value = e.detail.data.length == 0 ? [] : [0];
  105. console.warn(this.value);
  106. console.log('e:', e);
  107. },
  108. getLxSessionKey() {
  109. const that = this;
  110. uni.login({
  111. success(res) {
  112. console.error(res);
  113. that.getOpenId(res.code);
  114. },
  115. fail(res) {
  116. console.error(res);
  117. uni.hideLoading();
  118. }
  119. });
  120. },
  121. getOpenId(code) {
  122. const that = this;
  123. request.post('/wxma/code2Session', {
  124. code: code,
  125. platType: "slb",
  126. mpType: "engineer",
  127. }).then(res => {
  128. console.error(res);
  129. if (res.success) {
  130. that.lxSessionKey = res.resultMap.lxSessionKey;
  131. that.openId = res.resultMap.openId;
  132. that.unionid = res.resultMap.unionid;
  133. }
  134. })
  135. },
  136. getPhoneNumber(e) {
  137. if (!e.detail.errMsg || e.detail.errMsg != "getPhoneNumber:ok") {
  138. // wx.showModal({
  139. // title: '提示',
  140. // content: e.detail.errMsg,
  141. // showCancel: false
  142. // })
  143. console.error(e)
  144. return;
  145. }
  146. this.getLxSessionKey();
  147. setTimeout(() => {
  148. this._getPhoneNumber(e)
  149. }, 1000)
  150. },
  151. _getPhoneNumber(e) {
  152. console.warn(e);
  153. let that = this;
  154. if (e.detail.errMsg === 'getPhoneNumber:ok') {
  155. wx.getUserInfo({
  156. success: function(res) {
  157. console.error(res);
  158. res.encryptedData = encodeURIComponent(e.detail.encryptedData);
  159. res.iv = encodeURIComponent(e.detail.iv);
  160. res.lxSessionKey = that.lxSessionKey;
  161. that.getPhone(res)
  162. }
  163. })
  164. } else {
  165. uni.showToast({
  166. icon: 'none',
  167. title: e.detail.code ? '获取成功' : '拒绝了使用微信手机号'
  168. });
  169. }
  170. // if (res.code == 0) {
  171. // uni.showToast({
  172. // title: '绑定成功',
  173. // icon: 'success',
  174. // duration: 2000
  175. // })
  176. // this.$u.vuex('mobile', res.data)
  177. // this.form.mobile = res.data
  178. // } else {
  179. // uni.showModal({
  180. // title: '提示',
  181. // content: res.msg,
  182. // showCancel: false
  183. // })
  184. // }
  185. },
  186. getPhone(prarms) {
  187. let newParams = {};
  188. newParams.signature = prarms.signature;
  189. newParams.rawData = prarms.rawData;
  190. newParams.encryptedData = prarms.encryptedData;
  191. newParams.iv = prarms.iv;
  192. newParams.lxSessionKey = prarms.lxSessionKey;
  193. let that = this;
  194. request.post('/wxma/getWaUserPhone',
  195. newParams
  196. ).then(res => {
  197. console.error(res);
  198. if (res&&res.success) {
  199. this.ZhuceByPhone(res.resultMap.waUserPhoneInfo.phoneNumber);
  200. } else {
  201. uni.showToast({
  202. title: res.msg,
  203. icon: 'none'
  204. })
  205. }
  206. });
  207. },
  208. async ZhuceByPhone(phone) {
  209. const that = this;
  210. let params = {
  211. phone: phone,
  212. openid: that.openId,
  213. unionid: that.unionid,
  214. };
  215. that.canSave = false;
  216. const res = await request.post('/wxma/register',
  217. params, {
  218. header: {
  219. 'content-type': 'application/x-www-form-urlencoded',
  220. platType: "slb",
  221. mpType: "engineer",
  222. }
  223. }
  224. );
  225. if (res.success) {
  226. //当前页直接登录
  227. // uni.navigateTo({
  228. // url:'/pages/index/auth'
  229. // })
  230. uni.showToast({
  231. title: '请稍后',
  232. icon: 'none'
  233. })
  234. this.loginAgain();
  235. } else {
  236. uni.showToast({
  237. title: res.msg,
  238. icon: 'none'
  239. })
  240. }
  241. console.warn(res);
  242. },
  243. loginAgain() {
  244. let that = this;
  245. uni.login({
  246. success(res) {
  247. that.loginByCode(res.code);
  248. },
  249. fail(res) {
  250. uni.hideLoading();
  251. }
  252. });
  253. },
  254. loginByCode(frontId) {
  255. const that = this;
  256. uni.setStorageSync('loginStatus', 'false');
  257. wx.getUserInfo({
  258. success: function(res) {
  259. console.error(res);
  260. request.post("/slbMpAutoLogin", {
  261. code: frontId,
  262. appType: 'ma',
  263. encryptedData: res.encryptedData,
  264. iv: res.iv
  265. }, {
  266. login: false,
  267. warn: false,
  268. loading: false
  269. }).then(res2 => {
  270. console.error(res2);
  271. if (res2.success) {
  272. //登录成功
  273. uni.setStorageSync('loginStatus', 'true');
  274. uni.setStorageSync('userMap', JSON.stringify(res2.resultMap));
  275. uni.setStorageSync('userNo', res2.resultMap.accountName);
  276. that.getUserInfo();
  277. } else {
  278. //
  279. uni.showToast({
  280. title: res2.msg,
  281. icon: 'none'
  282. })
  283. that.canSave = true;
  284. //登录失败,
  285. }
  286. console.error(res2);
  287. });
  288. }
  289. })
  290. },
  291. getUserInfo() {
  292. let that = this;
  293. request.post('/slbWxma/getPersonlInfo', {
  294. }).then(res => {
  295. that.canSave = true;
  296. if (res.success) {
  297. that.personInfo = res.resultMap.userInfo || {};
  298. uni.setStorageSync('userInfo', JSON.stringify(res.resultMap.userInfo));
  299. uni.navigateBack();
  300. }
  301. console.warn(res);
  302. })
  303. },
  304. }
  305. }
  306. </script>
  307. <style lang="scss" scoped>
  308. .isHidden {
  309. visibility: hidden;
  310. }
  311. .template-edit {}
  312. /* 胶囊*/
  313. .tn-custom-nav-bar__back {
  314. width: 60%;
  315. height: 100%;
  316. position: relative;
  317. display: flex;
  318. justify-content: space-evenly;
  319. align-items: center;
  320. box-sizing: border-box;
  321. // background-color: rgba(0, 0, 0, 0.15);
  322. border-radius: 1000rpx;
  323. border: 1rpx solid rgba(255, 255, 255, 0.5);
  324. // color: #FFFFFF;
  325. font-size: 18px;
  326. .icon {
  327. display: block;
  328. flex: 1;
  329. margin: auto;
  330. text-align: center;
  331. }
  332. &:before {
  333. content: " ";
  334. width: 1rpx;
  335. height: 110%;
  336. position: absolute;
  337. top: 22.5%;
  338. left: 0;
  339. right: 0;
  340. margin: auto;
  341. transform: scale(0.5);
  342. transform-origin: 0 0;
  343. pointer-events: none;
  344. box-sizing: border-box;
  345. opacity: 0.7;
  346. background-color: #FFFFFF;
  347. }
  348. }
  349. /* 底部悬浮按钮 start*/
  350. .tn-tabbar-height {
  351. min-height: 100rpx;
  352. height: calc(120rpx + env(safe-area-inset-bottom) / 2);
  353. }
  354. .tn-footerfixed {
  355. position: fixed;
  356. width: 100%;
  357. bottom: calc(30rpx + env(safe-area-inset-bottom));
  358. z-index: 1024;
  359. box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0);
  360. }
  361. /* 底部悬浮按钮 end*/
  362. </style>