login.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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('https://slb-m.lx-device.com/webview?title=隐私协议&url='+'https://oss.lx-device.com/userFeedback/1734335349064Hno.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. },
  171. getPhone(prarms) {
  172. let newParams = {};
  173. newParams.signature = prarms.signature;
  174. newParams.rawData = prarms.rawData;
  175. newParams.encryptedData = prarms.encryptedData;
  176. newParams.iv = prarms.iv;
  177. newParams.lxSessionKey = prarms.lxSessionKey;
  178. let that = this;
  179. request.post('/wxma/getWaUserPhone',
  180. newParams
  181. ).then(res => {
  182. console.error(res);
  183. if (res&&res.success) {
  184. this.ZhuceByPhone(res.resultMap.waUserPhoneInfo.phoneNumber);
  185. } else {
  186. uni.showToast({
  187. title: res.msg,
  188. icon: 'none'
  189. })
  190. }
  191. });
  192. },
  193. async ZhuceByPhone(phone) {
  194. const that = this;
  195. let params = {
  196. phone: phone,
  197. openid: that.openId,
  198. unionid: that.unionid,
  199. };
  200. that.canSave = false;
  201. const res = await request.post('/wxma/register',
  202. params, {
  203. header: {
  204. 'content-type': 'application/x-www-form-urlencoded',
  205. platType: "slb",
  206. mpType: "engineer",
  207. }
  208. }
  209. );
  210. if (res.success) {
  211. //当前页直接登录
  212. // uni.navigateTo({
  213. // url:'/pages/index/auth'
  214. // })
  215. uni.showToast({
  216. title: '请稍后',
  217. icon: 'none'
  218. })
  219. this.loginAgain();
  220. } else {
  221. uni.showToast({
  222. title: res.msg,
  223. icon: 'none'
  224. })
  225. }
  226. console.warn(res);
  227. },
  228. loginAgain() {
  229. let that = this;
  230. uni.login({
  231. success(res) {
  232. that.loginByCode(res.code);
  233. },
  234. fail(res) {
  235. uni.hideLoading();
  236. }
  237. });
  238. },
  239. loginByCode(frontId) {
  240. const that = this;
  241. uni.setStorageSync('loginStatus', 'false');
  242. wx.getUserInfo({
  243. success: function(res) {
  244. console.error(res);
  245. request.post("/slbMpAutoLogin", {
  246. code: frontId,
  247. appType: 'ma',
  248. encryptedData: res.encryptedData,
  249. iv: res.iv
  250. }, {
  251. login: false,
  252. warn: false,
  253. loading: false
  254. }).then(res2 => {
  255. console.error(res2);
  256. if (res2.success) {
  257. //登录成功
  258. uni.setStorageSync('loginStatus', 'true');
  259. uni.setStorageSync('userMap', JSON.stringify(res2.resultMap));
  260. uni.setStorageSync('userNo', res2.resultMap.accountName);
  261. that.getUserInfo();
  262. } else {
  263. //
  264. uni.showToast({
  265. title: res2.msg,
  266. icon: 'none'
  267. })
  268. that.canSave = true;
  269. //登录失败,
  270. }
  271. console.error(res2);
  272. });
  273. }
  274. })
  275. },
  276. getUserInfo() {
  277. let that = this;
  278. request.post('/slbWxma/getPersonlInfo', {
  279. }).then(res => {
  280. that.canSave = true;
  281. if (res.success) {
  282. that.personInfo = res.resultMap.userInfo || {};
  283. uni.setStorageSync('userInfo', JSON.stringify(res.resultMap.userInfo));
  284. uni.navigateBack();
  285. }
  286. console.warn(res);
  287. })
  288. },
  289. }
  290. }
  291. </script>
  292. <style lang="scss" scoped>
  293. .isHidden {
  294. visibility: hidden;
  295. }
  296. .template-edit {}
  297. /* 胶囊*/
  298. .tn-custom-nav-bar__back {
  299. width: 60%;
  300. height: 100%;
  301. position: relative;
  302. display: flex;
  303. justify-content: space-evenly;
  304. align-items: center;
  305. box-sizing: border-box;
  306. // background-color: rgba(0, 0, 0, 0.15);
  307. border-radius: 1000rpx;
  308. border: 1rpx solid rgba(255, 255, 255, 0.5);
  309. // color: #FFFFFF;
  310. font-size: 18px;
  311. .icon {
  312. display: block;
  313. flex: 1;
  314. margin: auto;
  315. text-align: center;
  316. }
  317. &:before {
  318. content: " ";
  319. width: 1rpx;
  320. height: 110%;
  321. position: absolute;
  322. top: 22.5%;
  323. left: 0;
  324. right: 0;
  325. margin: auto;
  326. transform: scale(0.5);
  327. transform-origin: 0 0;
  328. pointer-events: none;
  329. box-sizing: border-box;
  330. opacity: 0.7;
  331. background-color: #FFFFFF;
  332. }
  333. }
  334. /* 底部悬浮按钮 start*/
  335. .tn-tabbar-height {
  336. min-height: 100rpx;
  337. height: calc(120rpx + env(safe-area-inset-bottom) / 2);
  338. }
  339. .tn-footerfixed {
  340. position: fixed;
  341. width: 100%;
  342. bottom: calc(30rpx + env(safe-area-inset-bottom));
  343. z-index: 1024;
  344. box-shadow: 0 1rpx 6rpx rgba(0, 0, 0, 0);
  345. }
  346. /* 底部悬浮按钮 end*/
  347. </style>