pcLogin.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <view class="pcLogins">
  3. <u-navbar :is-back="false" title="登录" :border-bottom="false" title-color="#333333" back-icon-color="#ffffff">
  4. </u-navbar>
  5. <u-line color="#D6D6DB" />
  6. <view class="contents">
  7. <!-- 正文内容 -->
  8. <image class="logo" :src="SCAN_LOGO" style="width: 360rpx; height: 72rpx"></image>
  9. <text>登录后您可在网页端继续浏览课程</text>
  10. <!-- #ifdef H5 -->
  11. <view class="login_box" v-show="showinput">
  12. <u-form :model="form" ref="uForm1">
  13. <u-form-item prop="account"><u-input type="idcard" v-model="form.account"
  14. placeholder-style="color:#999999" placeholder="手机号/学员身份证" /></u-form-item>
  15. <u-form-item prop="pwd"><u-input class="password" v-model="form.pwd"
  16. placeholder-style="color:#999999" type="password" placeholder="登录密码" /></u-form-item>
  17. </u-form>
  18. </view>
  19. <view class="login_bt" @click="pcLogin()">微信登录</view>
  20. <!-- #endif -->
  21. <!-- #ifdef MP-WEIXIN -->
  22. <button type="default" open-type="getPhoneNumber" @getphonenumber="wxLogin" class="login_bt">
  23. 微信登录
  24. </button>
  25. <!-- #endif -->
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import configjs from "@/common/config";
  31. import {
  32. getCode
  33. } from "@/utils/authority";
  34. import {
  35. mapGetters,
  36. mapActions
  37. } from "vuex";
  38. export default {
  39. data() {
  40. return {
  41. SCAN_LOGO: configjs.SCAN_LOGO,
  42. scanCode: "", // 获取扫码的路径最后面的6位标识码
  43. code: "sss",
  44. gzhOpenid: "",
  45. showinput: false,
  46. isUse: false,
  47. form: {
  48. account: "",
  49. pwd: "",
  50. },
  51. rules: {
  52. account: [{
  53. required: true,
  54. message: "请输入手机号/学员身份证",
  55. trigger: ["change"],
  56. }, ],
  57. pwd: [{
  58. required: true,
  59. message: "请输入密码",
  60. // 可以单个或者同时写两个触发验证方式
  61. trigger: ["change"],
  62. }, ],
  63. },
  64. };
  65. },
  66. onLoad(query) {
  67. console.log("扫描后得1:", query);
  68. const q = decodeURIComponent(query.q);
  69. if (query.acc && query.pwd) {
  70. const acc = decodeURIComponent(query.acc);
  71. const pwd = decodeURIComponent(query.pwd);
  72. this.form.account = acc;
  73. this.form.pwd = pwd;
  74. }
  75. this.scanCode = q.substring(q.length - 6);
  76. console.log("扫描后得:", q, this.scanCode, this.form.account);
  77. // 扫描二维码后调用,小程序已扫码
  78. if (this.scanCode) {
  79. this.$api.scanhasCode({
  80. scanCode: this.scanCode
  81. }).then((res) => {
  82. console.log("调用扫码接口返回的:", res);
  83. if (res.data.code == 200) {
  84. console.log();
  85. }
  86. });
  87. }
  88. // 获取code
  89. // #ifdef MP-WEIXIN
  90. this.getwxCode();
  91. // #endif
  92. // #ifdef H5
  93. this.getWXCodeh5(1);
  94. // #endif
  95. },
  96. onShow() {},
  97. computed: {
  98. ...mapGetters(["config"]),
  99. },
  100. methods: {
  101. topclogin() {
  102. this.$api
  103. .check_gzh_openId({
  104. code: this.code,
  105. account: this.form.account,
  106. password: this.form.pwd,
  107. gzhOpenid: this.gzhOpenid,
  108. })
  109. .then((res) => {
  110. if (res.data.code == 200) {
  111. if (res.data.data.gzhStatus == 1) {
  112. this.loginCallback(res);
  113. } else {
  114. this.$u.toast("请输入账号密码绑定微信登录");
  115. this.showinput = true;
  116. if (res.data.data.gzhOpenid) {
  117. this.gzhOpenid = res.data.data.gzhOpenid;
  118. }
  119. // this.getWXCodeh5(0);A
  120. }
  121. } else {
  122. this.$u.toast(res.data.msg);
  123. // this.getWXCodeh5(0);
  124. }
  125. });
  126. },
  127. pcLogin() {
  128. let that = this;
  129. if (this.showinput) {
  130. if (!this.form.account) {
  131. this.$u.toast("请输入手机号码/身份证号");
  132. return;
  133. }
  134. if (!this.form.pwd) {
  135. this.$u.toast("请输入密码");
  136. return;
  137. }
  138. }
  139. if (this.gzhOpenid) {
  140. this.topclogin();
  141. } else {
  142. this.getWXCodeh5(0);
  143. }
  144. },
  145. // 获取code并登录
  146. getWXCodeh5(totype) {
  147. var code = this.getUrlCode().code; //是否存在code
  148. if (code == this.code) {
  149. code = '';
  150. }
  151. let url = location.href //授权后重定向的回调链接地址
  152. let url2 = 'https://' + window.location.host + "/pages4/login/pcLogin?q=" + this.scanCode;
  153. if (totype == 0) {
  154. url2 = url2 + "&acc=" + this.form.account + "&pwd=" + this.form.pwd
  155. }
  156. console.log("dasdsada1", url2);
  157. // let code =getCode(url2);
  158. if (code == null || code === "") {
  159. this.$api.mobileConfig().then((res0) => {
  160. // console.log("res0",res0);
  161. var gzhSelfLicense=false;
  162. let data = res0.data.rows.find((e) => e.configKey == "home.mobile");
  163. if (data) {
  164. var config1 = JSON.parse(data.configValue) || {}
  165. gzhSelfLicense=config1.gzhSelfLicense;
  166. console.log('gzhSelfLicense',config1.gzhSelfLicense,gzhSelfLicense)
  167. }
  168. if (gzhSelfLicense) {
  169. this.$api.getWxConfig().then((res) => {
  170. console.log("res", res);
  171. let appid = res.data.data.gzhAppId //公众号的唯一标识
  172. window.location.replace('https://open.weixin.qq.com/connect/oauth2/authorize?appid=' +
  173. appid + '&redirect_uri=' + encodeURIComponent(url2) +
  174. '&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect')
  175. });
  176. } else {
  177. url2 = url2.split("//")[1];
  178. location.replace("https://www.xyyxt.net/home/index2?ask_type=" + url2);
  179. }
  180. });
  181. } else {
  182. this.code = code;
  183. console.log("dasdsada2", this.code);
  184. //此处调用后端提供的接口,传入获取到的code换取access_token
  185. if (totype == 1) {
  186. this.topclogin();
  187. } else if (totype == 0) {
  188. this.topclogin();
  189. }
  190. }
  191. // this.$api.getWxConfig().then((res) => {
  192. // console.log("res", res);
  193. // let appid = res.data.data.gzhAppId //公众号的唯一标识
  194. // });
  195. },
  196. // 截取url中的code方法
  197. getUrlCode() {
  198. // 截取url中的code方法
  199. var url = location.search;
  200. var theRequest = new Object();
  201. if (url.indexOf("?") != -1) {
  202. var str = url.substr(1);
  203. var strs = str.split("&");
  204. for (var i = 0; i < strs.length; i++) {
  205. theRequest[strs[i].split("=")[0]] = strs[i].split("=")[1];
  206. }
  207. }
  208. return theRequest;
  209. },
  210. getwxCode() {
  211. uni.login({
  212. provider: "weixin",
  213. success: (loginRes) => {
  214. this.code = loginRes.code;
  215. console.log("获取的code:", this.code);
  216. },
  217. fail: (err) => {
  218. // this.code = 'fff';
  219. console.log(this.code)
  220. },
  221. complete: (com) => {
  222. // this.code = 'ccc';
  223. console.log(this.code)
  224. },
  225. });
  226. },
  227. wxLogin(e) {
  228. this.$api
  229. .wxLogin({
  230. code: this.code,
  231. encryptedData: e.detail.encryptedData,
  232. iv: e.detail.iv,
  233. })
  234. .then((res) => {
  235. if (res.data.code == 200) {
  236. this.loginCallback(res);
  237. } else {
  238. if (res.data.code == 666) {
  239. this.$u.toast(res.data.msg);
  240. setTimeout(() => {
  241. uni.navigateTo({
  242. url: "/pages2/register/register",
  243. });
  244. }, 500);
  245. return;
  246. }
  247. this.getwxCode(); // code用完一次就会过期,防止用户点击取消后再点微信登录后code过期
  248. }
  249. });
  250. },
  251. // 微信登录成功的回调
  252. loginCallback(res) {
  253. // console.log('登录后的回调',res)
  254. // if(res.data.data && res.data.data.full_info){
  255. //信息完善,直接进入页面
  256. uni.setStorageSync("user_account", res.data.data.user_account);
  257. uni.setStorageSync("token", res.data.data.token);
  258. // /app/user/getInfo 登录用户信息// fromPlat来源平台 1小程序 2PC网站
  259. this.$api.getInfo({
  260. fromPlat: 1
  261. }).then((resdata) => {
  262. if (resdata.data.code == 200) {
  263. this.$store.state.userInfo = resdata.data.data;
  264. this.submitCode();
  265. }
  266. });
  267. // } else {
  268. // //未完善信息,存为临时信息
  269. // uni.setStorageSync('user_account_temp', res.data.data.user_account);
  270. // uni.setStorageSync('token_temp', res.data.data.token);
  271. // this.$navTo.togo('/pages2/register/bind', {scanCode: this.scanCode})
  272. // }
  273. },
  274. // scanLoginCheck小程序校验PC登录二维码,执行登录获取到令牌,然后把扫码的路径最后面的6位标识码提交给后台就行
  275. submitCode() {
  276. this.$api
  277. .scanLoginCheck({
  278. scanCode: this.scanCode,
  279. })
  280. .then((res) => {
  281. if (res.data.code == 200) {
  282. uni.navigateTo({
  283. url: "/pages4/login/pcLoginSuccess",
  284. });
  285. } else {
  286. this.$u.toast(res.data.msg);
  287. }
  288. });
  289. },
  290. pwlogin() {
  291. let that = this;
  292. if (!this.form.account) {
  293. this.$u.toast("请输入手机号码/身份证号");
  294. return;
  295. }
  296. if (!this.form.pwd) {
  297. this.$u.toast("请输入密码");
  298. return;
  299. }
  300. //虚拟登录
  301. /* that.fakeLogin()
  302. return */
  303. that.isUse = true;
  304. let form = JSON.parse(JSON.stringify(this.form));
  305. form.pwd = this.encryptor(form.pwd);
  306. form["shareActivityCode"] = this.shareActivityCode;
  307. // 账号登录用户 /app/common/account_login
  308. that.$api.accountLogin(form).then(
  309. (res) => {
  310. that.isUse = false;
  311. if (res.data.code == 200) {
  312. this.loginCallback(res, "pwlogin");
  313. } else if (res.data.code == 699) {
  314. uni.showModal({
  315. title: '温馨提示',
  316. content: "系统升级中,请点击按钮 “复制” 链接,打开手机浏览器,粘贴登录即可学习",
  317. confirmText: "复制",
  318. success: (result) => {
  319. if (result.confirm) {
  320. uni.setClipboardData({
  321. data: res.data.msg,
  322. success: function() {
  323. uni.showToast({
  324. title: '链接已复制成功',
  325. icon: 'none',
  326. duration: 2000
  327. });
  328. }
  329. })
  330. } else if (result.cancel) {
  331. console.log('用户点击取消');
  332. }
  333. }
  334. });
  335. } else {
  336. that.$u.toast(res.data.msg);
  337. }
  338. },
  339. (err) => {
  340. that.isUse = false;
  341. }
  342. );
  343. },
  344. },
  345. };
  346. </script>
  347. <style lang="scss" scoped>
  348. .contents {
  349. width: 100%;
  350. height: 100%;
  351. text-align: center;
  352. display: flex;
  353. flex-direction: column;
  354. align-items: center;
  355. .logo {
  356. margin: 90rpx 0rpx 250rpx;
  357. }
  358. >text {
  359. font-size: 22rpx;
  360. color: #666;
  361. }
  362. .login_bt {
  363. width: 400rpx;
  364. height: 70rpx;
  365. line-height: 70rpx;
  366. text-align: center;
  367. background: #09ba08;
  368. color: #fff;
  369. font-size: 28rpx;
  370. border-radius: 35rpx;
  371. margin-top: 20rpx;
  372. }
  373. }
  374. .login_box {
  375. width: 80%;
  376. height: 360rpx;
  377. background: #ffffff;
  378. box-shadow: 0rpx 0rpx 16rpx 4rpx rgba(1, 99, 235, 0.1);
  379. border-radius: 24rpx;
  380. margin-top: 30rpx;
  381. padding: 40rpx 35rpx;
  382. .password {
  383. /deep/.uicon-eye-fill {
  384. &::before {
  385. color: #007aff;
  386. content: "\e613";
  387. }
  388. }
  389. }
  390. }
  391. </style>