login.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. <template>
  2. <view class="page">
  3. <view class="header">
  4. <!-- <view class="left"> -->
  5. <!-- <image class="img" mode="widthFix" src="../../static/login/close.png"></image> -->
  6. <!-- </view> -->
  7. <view class="title">登录/注册</view>
  8. <view class="subtitle">手机号登录/注册</view>
  9. </view>
  10. <view class="tbody">
  11. <!-- <view class="tbody" style="position: fixed;top: 70%;left: 50%;transform: translate(-50%,-50%);"> -->
  12. <block v-if="type == 'onelogin'">
  13. <image class="icon" mode="widthFix" src="../../static/me/avator.png"></image>
  14. <text class="mobile">+ 86 1**********</text>
  15. <text class="tips">首次验证通过即注册萌创星球账号</text>
  16. <text class="btn_submit blick-btn-animation">本机号码一键登录</text>
  17. <view class="other">
  18. <view class="pass" @click="type = 'pass'">密码登录</view>
  19. <view class="line"></view>
  20. <view class="mob" @click="type = 'mobile'">手机号登录</view>
  21. </view>
  22. </block>
  23. <block v-if="type == 'pass' || type == 'mobile'">
  24. <template v-if="isSmsLogin">
  25. <view class="name">手机号码:</view>
  26. <view class="item">
  27. <input type="number" class="input" v-model="mobile" placeholder="请输入手机号码" maxlength="11" />
  28. </view>
  29. <block v-if="type == 'pass'">
  30. <view class="name">登录密码:</view>
  31. <view class="item">
  32. <input type="password" class="input" v-model="password" placeholder="请输入登录密码"
  33. maxlength="32" />
  34. </view>
  35. <view class="other_list">
  36. <text class="left" v-if="true" @click="type = 'mobile'">验证码登录</text>
  37. <text class="left" v-else></text>
  38. <text class="right" @click="type = 'mobile'" v-if="false">验证码登录</text>
  39. <text class="right" @click="toRegist">还没有账号?开始注册</text>
  40. </view>
  41. </block>
  42. <block v-if="type == 'mobile'">
  43. <view class="name">验证码:</view>
  44. <view class="item">
  45. <input type="text" class="input" v-model="code" placeholder="请输入验证码" maxlength="6" />
  46. <view class="btn blick-btn-animation" v-if="captchaTime === 0" @click="getCode">获取验证码</view>
  47. <view class="btn" v-if="captchaTime > 0">{{ captchaTime }}秒后重试</view>
  48. </view>
  49. <view class="other_list" v-if="false">
  50. <text class="left"></text>
  51. <text class="right" @click="type = 'pass'" style="color: blue;">密码登录</text>
  52. </view>
  53. </block>
  54. <text class="btn_submit white" @click="toLogin">登录/注册</text>
  55. <text class="btn_submit blick-btn-animation" @click="oneClickLoginFun">一键登录</text>
  56. </template>
  57. <template v-else>
  58. <view style="width: 100%;height: 500rpx;display: flex;justify-content: center;align-items: flex-end;">
  59. <text class="btn_submit blick-btn-animation" @click="oneClickLoginFun">一键登录</text>
  60. </view>
  61. </template>
  62. </block>
  63. <view class="wechat" v-if="false">
  64. <image class="img" mode="widthFix" src="../../static/login/wechat.png"></image>
  65. </view>
  66. <view class="agree">
  67. <view class="agree2" @click="agreeChk()">
  68. <image mode="widthFix" src="../../static/icon/wd_icon_gouxuan04.png" v-if="is_agree == 0"></image>
  69. <image mode="widthFix" src="../../static/icon/wd_icon_gouxuan05.png" v-if="is_agree == 1"></image>
  70. <text>我已阅读并同意</text>
  71. </view>
  72. <text class="xy" @click="goWeb('https://e.zhichao.art/web/yszc.php', '隐私协议')">
  73. 隐私协议
  74. </text>
  75. 》和《
  76. <text class="xy" @click="goWeb('https://e.zhichao.art/web/yhxy.php', '用户使用协议')">
  77. 用户使用协议
  78. </text>
  79. </view>
  80. <view class="agree" v-if="false"><text class="agree2">{{ push_token }}</text></view>
  81. </view>
  82. <view class="blankHeight"></view>
  83. <DialogBox ref="DialogBox"></DialogBox>
  84. </view>
  85. </template>
  86. <script>
  87. import pubc from '@/common/public.js'
  88. import { mapState } from 'vuex'
  89. export default {
  90. components: {},
  91. computed: {
  92. ...mapState('hideModule', ['isSmsLogin'])
  93. },
  94. data() {
  95. return {
  96. skey: '',
  97. sel: 1,
  98. is_agree: 0,
  99. type: 'mobile',
  100. myinfo: {
  101. nickname: '',
  102. join_name: '',
  103. num_1: 0,
  104. num_2: 0,
  105. num_3: 0,
  106. num_4: 0,
  107. is_login: 'no',
  108. num_history: 0,
  109. num_collection: 0
  110. },
  111. mobile: '',
  112. password: '',
  113. code: '',
  114. captchaTime: 0,
  115. push_token: '',
  116. lat: '',
  117. lng: '',
  118. univerifyStyle: {
  119. "fullScreen": false, // 是否全屏显示,默认值: false
  120. "backgroundColor": "#ffffff", // 授权页面背景颜色,默认值:#ffffff
  121. "backgroundImage": "", // 全屏显示的背景图片,默认值:"" (仅支持本地图片,只有全屏显示时支持)
  122. "icon": {
  123. "path": "/static/logo.png", // 自定义显示在授权框中的logo,仅支持本地图片 默认显示App logo
  124. "width": "60px", //图标宽度 默认值:60px
  125. "height": "60px" //图标高度 默认值:60px
  126. },
  127. "closeIcon": {
  128. // "path": "/static/icon/whiteBackground.png", // 自定义显示在授权框中的取消图片,仅支持本地图片
  129. "width": "60px", //图标宽度 默认值:60px (HBuilderX 4.0+ 仅iOS支持)
  130. "height": "60px" //图标高度 默认值:60px (HBuilderX 4.0+ 仅iOS支持)
  131. },
  132. "phoneNum": {
  133. "color": "#202020" // 手机号文字颜色 默认值:#202020
  134. },
  135. "slogan": {
  136. "color": "#BBBBBB" // slogan 字体颜色 默认值:#BBBBBB
  137. },
  138. "authButton": {
  139. "normalColor": "#131313", // 授权按钮正常状态背景颜色 默认值:#3479f5
  140. "highlightColor": "#131313", // 授权按钮按下状态背景颜色 默认值:#2861c5(仅ios支持)
  141. "disabledColor": "#73aaf5", // 授权按钮不可点击时背景颜色 默认值:#73aaf5(仅ios支持)
  142. "textColor": "#ffffff", // 授权按钮文字颜色 默认值:#ffffff
  143. "title": "本机号码一键登录", // 授权按钮文案 默认值:"本机号码一键登录"
  144. "borderRadius": "24px" // 授权按钮圆角 默认值:"24px" (按钮高度的一半)
  145. },
  146. "otherLoginButton": {
  147. "visible": false, // 是否显示其他登录按钮,默认值:true
  148. "normalColor": "", // 其他登录按钮正常状态背景颜色 默认值:透明
  149. "highlightColor": "", // 其他登录按钮按下状态背景颜色 默认值:透明
  150. "textColor": "#656565", // 其他登录按钮文字颜色 默认值:#656565
  151. "title": "其他登录方式", // 其他登录方式按钮文字 默认值:“其他登录方式”
  152. "borderColor": "", //边框颜色 默认值:透明(仅iOS支持)
  153. "borderRadius": "0px" // 其他登录按钮圆角 默认值:"24px" (按钮高度的一半)
  154. },
  155. "privacyTerms": {
  156. "defaultCheckBoxState": true, // 条款勾选框初始状态 默认值: true
  157. "isCenterHint": true, //未勾选服务条款时点击登录按钮的提示是否居中显示 默认值: false (3.7.13+ 版本支持)
  158. "uncheckedImage": "/static/icon/wd_icon_gouxuan04.png", // 可选 条款勾选框未选中状态图片(仅支持本地图片 建议尺寸 24x24px)(3.2.0+ 版本支持)
  159. "checkedImage": "/static/icon/wd_icon_gouxuan05.png", // 可选 条款勾选框选中状态图片(仅支持本地图片 建议尺寸24x24px)(3.2.0+ 版本支持)
  160. "checkBoxSize": 16, // 可选 条款勾选框大小
  161. "textColor": "#BBBBBB", // 文字颜色 默认值:#BBBBBB
  162. "termsColor": "#5496E3", // 协议文字颜色 默认值: #5496E3
  163. "prefix": "我已阅读并同意", // 条款前的文案 默认值:“我已阅读并同意”
  164. "suffix": "并使用本机号码登录", // 条款后的文案 默认值:“并使用本机号码登录”
  165. "privacyItems": [ // 自定义协议条款,最大支持2个,需要同时设置url和title. 否则不生效
  166. {
  167. "url": "https://e.zhichao.art/web/yszc.php", // 点击跳转的协议详情页面
  168. "title": "隐私协议" // 协议名称
  169. },
  170. {
  171. "url": "https://e.zhichao.art/web/yhxy.php", // 点击跳转的协议详情页面
  172. "title": "用户使用协议" // 协议名称
  173. }
  174. ]
  175. },
  176. "buttons": { // 自定义页面下方按钮仅全屏模式生效(3.1.14+ 版本支持)
  177. "iconWidth": "45px", // 图标宽度(高度等比例缩放) 默认值:45px
  178. "list": [
  179. {
  180. "provider": "apple",
  181. // "iconPath": "/static/apple.png" // 图标路径仅支持本地图片
  182. },
  183. {
  184. "provider": "weixin",
  185. // "iconPath": "/static/wechat.png" // 图标路径仅支持本地图片
  186. }
  187. ]
  188. }
  189. }
  190. }
  191. },
  192. onLoad() {
  193. setTimeout(function () {
  194. console.log(this.isSmsLogin, 'isSmsLogin');
  195. uni.setNavigationBarColor({
  196. frontColor: '#ffffff',
  197. backgroundColor: '#00000000',
  198. animation: {
  199. duration: 400,
  200. timingFunc: 'easeIn'
  201. }
  202. })
  203. }, 200);
  204. let that = this;
  205. uni.getPushClientId({
  206. success: (res) => {
  207. console.log("su:", res.cid);
  208. that.push_token = res.cid;
  209. },
  210. fail(err) {
  211. that.push_token = '';
  212. console.log(err)
  213. }
  214. });
  215. this.oneClickLoginFun();
  216. },
  217. onShow() {
  218. // let hsign = pubc.Encrypt("aboa-wifl-kwfl-zjfk-wlaa_FA0412932BAE9D98506580ADB348BEF9");
  219. // console.log("hsign", hsign)
  220. // let skey = uni.getStorageSync("wapptoken");
  221. // if (skey != null && skey != "" && skey != undefined) {
  222. // uni.switchTab({
  223. // url: "/pages/index/index"
  224. // });
  225. // return;
  226. // }
  227. // let that = this;
  228. // uni.getLocation({
  229. // type: 'wgs84',
  230. // success: function(res) {
  231. // that.lat = res.latitude;
  232. // that.lng = res.longitude;
  233. // },
  234. // fail: function(error) {
  235. // console.error('获取位置失败:', error);
  236. // }
  237. // });
  238. },
  239. methods: {
  240. goWeb(url, title) {
  241. uni.navigateTo({
  242. url: `/pages/webview/index?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title)}`
  243. })
  244. },
  245. onBack() { },
  246. agreeChk() {
  247. if (this.is_agree == 0) {
  248. this.is_agree = 1;
  249. } else {
  250. this.is_agree = 0;
  251. }
  252. },
  253. goPage(page) {
  254. if (page == 'yhxy') {
  255. uni.navigateTo({
  256. url: '/pages/AboutUs/yhxy'
  257. })
  258. } else if (page == 'yszc') {
  259. // #ifdef APP-PLUS
  260. plus.runtime.openWeb('https://e.zhichao.art/web/yszc.php') // plus.runtime.openWeb(href);
  261. // #endif
  262. // #ifdef H5
  263. window.open('https://e.zhichao.art/web/yszc.php')
  264. // #endif
  265. // uni.navigateTo({
  266. // url: '/pages/AboutUs/yszc'
  267. // })
  268. } else {
  269. uni.navigateTo({
  270. url: page,
  271. });
  272. }
  273. },
  274. toRegist() {
  275. uni.navigateTo({
  276. url: "/pages/login/reg",
  277. });
  278. },
  279. toLogin() {
  280. let that = this;
  281. if (this.mobile.length != 11) {
  282. uni.showToast({
  283. title: "请输入手机号",
  284. icon: "none",
  285. });
  286. return;
  287. }
  288. if (this.type == 'pass') {
  289. if (this.password.length < 6) {
  290. uni.showToast({
  291. title: "请输入不小于6位的密码",
  292. icon: "none",
  293. });
  294. return;
  295. }
  296. } else {
  297. if (this.code.length < 4) {
  298. uni.showToast({
  299. title: "请输入手机验证码",
  300. icon: "none",
  301. });
  302. return;
  303. }
  304. }
  305. if (this.is_agree == 0) {
  306. uni.showToast({
  307. title: "请确认并选择协议",
  308. icon: "none",
  309. });
  310. return;
  311. }
  312. let method = '/Member/gamelogin';
  313. if (this.btn_type == 'reg') {
  314. method = '/Member/register';
  315. if (this.code.length < 4) {
  316. uni.showToast({
  317. title: '请输入验证码',
  318. icon: 'none'
  319. });
  320. return;
  321. }
  322. } else if (this.btn_type == 'reset') {
  323. method = '/Member/resetPass';
  324. if (this.code.length < 4) {
  325. uni.showToast({
  326. title: '请输入验证码',
  327. icon: 'none'
  328. });
  329. return;
  330. }
  331. }
  332. this.loginInterface({ isOneClickLogin: false, phone: '' },)
  333. },
  334. loginInterface({ isOneClickLogin, phone }) {
  335. let that = this;
  336. let channel = "";
  337. // #ifdef APP-PLUS
  338. channel = plus.runtime.channel;
  339. // #endif
  340. uni.showLoading({
  341. mask: true,
  342. });
  343. console.log("host", this.$apiHost + method);
  344. let mobile = this.mobile;
  345. let code = this.code;
  346. let type = this.type;
  347. console.log(type, 89);
  348. let method = '/Member/gamelogin';
  349. if (isOneClickLogin) {
  350. mobile = phone;
  351. code = '123601';
  352. type = 'mobile';
  353. }
  354. uni.request({
  355. url: this.$apiHost + method,
  356. data: {
  357. uuid: getApp().globalData.uuid,
  358. channel: channel,
  359. loginType: type,
  360. mobile,
  361. password: this.password,
  362. code,
  363. push_token: this.push_token,
  364. lat: this.lat,
  365. lng: this.lng,
  366. },
  367. header: {
  368. "content-type": "application/json",
  369. },
  370. success: (res) => {
  371. console.log("----", res.data);
  372. if (res.data.success == "yes") {
  373. uni.showToast({
  374. title: "登录成功",
  375. icon: "none",
  376. });
  377. console.log("res.data", res.data);
  378. if (res.data.uuid.length > 5) {
  379. uni.setStorageSync("app_uuid", res.data.uuid);
  380. getApp().globalData.uuid = res.data.uuid;
  381. }
  382. uni.setStorageSync("is_login", "yes");
  383. uni.setStorageSync("wapptoken", res.data.skey);
  384. getApp().globalData.skey = res.data.skey;
  385. if (res.data.header_c != "") {
  386. getApp().globalData.headerSign = pubc.Encrypt(res.data.header_c + "_" +
  387. getApp().globalData.uuid);
  388. uni.setStorageSync("headerSign", getApp().globalData.headerSign);
  389. }
  390. getApp().globalData.headerC = res.data.header_c;
  391. if (res.data.nickname == '') {
  392. uni.redirectTo({
  393. url: '/pages/my/step'
  394. });
  395. return;
  396. }
  397. // 获取用户信息储存全局
  398. uni.request({
  399. url: this.$apiHost + '/User/getinfo',
  400. data: {
  401. uuid: getApp().globalData.uuid,
  402. skey: getApp().globalData.skey
  403. },
  404. header: {
  405. "content-type": "application/json",
  406. 'sign': getApp().globalData.headerSign
  407. },
  408. success: (res) => {
  409. console.log("--获取用户信息--:", res.data);
  410. if (res.data.need_login == "yes") {
  411. }
  412. if (res.data.aihao) {
  413. this.aihao_tags = res.data.aihao.split(",");
  414. }
  415. if (res.data.nickname) {
  416. getApp().globalData.nickname = res.data.nickname
  417. uni.removeStorageSync("nickname");
  418. uni.setStorageSync("nickname", res.data.nickname);
  419. }
  420. if (res.data.mobile) {
  421. getApp().globalData.mobile = res.data.mobile
  422. uni.removeStorageSync("mobile", res.data.mobile);
  423. uni.setStorageSync("mobile", res.data.mobile);
  424. }
  425. if (res.data.user_id) {
  426. getApp().globalData.user_id = res.data.user_id
  427. uni.removeStorageSync("user_id");
  428. uni.setStorageSync("user_id", res.data.user_id);
  429. }
  430. if (res.data.avator) {
  431. getApp().globalData.avator = res.data.avator
  432. uni.removeStorageSync("avator");
  433. uni.setStorageSync("avator", res.data.avator);
  434. }
  435. },
  436. complete: (com) => {
  437. // uni.hideLoading();
  438. },
  439. fail: (e) => {
  440. console.log("----e:", e);
  441. }
  442. });
  443. uni.switchTab({
  444. url: "/pages/index/index",
  445. });
  446. } else if (res.data.success == "no") {
  447. uni.showToast({
  448. title: res.data.str,
  449. icon: "none",
  450. });
  451. } else {
  452. uni.showToast({
  453. title: "操作失败,请联系客服",
  454. icon: "none",
  455. });
  456. }
  457. },
  458. complete: (com) => {
  459. uni.hideLoading();
  460. },
  461. });
  462. },
  463. getCode() {
  464. if (this.mobile.length != 11) {
  465. uni.showToast({
  466. title: '请输入手机号',
  467. icon: 'none'
  468. });
  469. return;
  470. }
  471. if (this.captchaTime > 0) {
  472. uni.showToast({
  473. title: '不能重复获取',
  474. icon: 'none'
  475. });
  476. return;
  477. }
  478. this.captchaTime = 60;
  479. uni.request({
  480. url: this.$apiHost + '/Web/getcode', //仅为示例,并非真实接口地址。
  481. data: {
  482. skey: this.skey,
  483. mobile: this.mobile,
  484. },
  485. header: {
  486. 'content-type': 'application/json' //自定义请求头信息
  487. },
  488. success: (res) => {
  489. console.log("----", res.data)
  490. uni.showToast({
  491. title: res.data.str,
  492. icon: 'none'
  493. })
  494. if (res.data.success == 'yes') {
  495. this.getCodeTime();
  496. } else {
  497. this.captchaTime = 0;
  498. }
  499. }
  500. });
  501. },
  502. getCodeTime() {
  503. if (this.captchaTime > 0) {
  504. setTimeout(() => {
  505. this.captchaTime--;
  506. this.getCodeTime();
  507. }, 1000);
  508. }
  509. },
  510. oneClickLoginFun() {
  511. let _this = this;
  512. //预登陆
  513. uni.preLogin({
  514. provider: 'univerify',
  515. success() { //预登录成功
  516. // 显示一键登录选项
  517. uni.login({
  518. provider: 'univerify',
  519. univerifyStyle: _this.univerifyStyle,
  520. success(res) { // 登录成功
  521. console.log(res.authResult.access_token);
  522. console.log(res.authResult.openid);
  523. // 此处获取了openid和access_token
  524. // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
  525. // 通过uniCloud.callFunction函数实现前端获取手机号
  526. uniCloud.callFunction({
  527. name: "oneClickLogin", // 填写你自己的云函数名称
  528. //传入上面获取的openid和access_token获取手机号
  529. data: {
  530. access_token: res.authResult.access_token, // 客户端一键登录接口返回的access_token
  531. openid: res.authResult.openid // 客户端一键登录接口返回的openid
  532. }
  533. }).then((dataRes) => {
  534. //此处已经成功获取手机号等信息
  535. console.log("云函数返回的参数1", dataRes)
  536. let phone = dataRes.result.data.phoneNumber
  537. if (phone) {
  538. _this.loginInterface({
  539. isOneClickLogin: true,
  540. phone,
  541. })
  542. setTimeout(() => {
  543. uni.closeAuthView() //关闭一键登录弹出窗口
  544. }, 500)
  545. } else {
  546. }
  547. // 获取手机号后根据自己的需求做后面的登录操作即可
  548. //...
  549. }).catch((err) => {
  550. console.log(err);
  551. console.log("云函数报错", err)
  552. uni.showToast({
  553. title: err.errMsg,
  554. icon: "none"
  555. })
  556. this_ = this
  557. setTimeout(() => {
  558. uni.closeAuthView() //关闭一键登录弹出窗口
  559. _this.onClickMsgLogin()
  560. uni.showToast({
  561. title: "请插入SIM卡并且使用流量后再重试",
  562. icon: "none"
  563. })
  564. }, 500)
  565. })
  566. },
  567. fail(res) { // 登录失败
  568. console.log(res.errCode)
  569. console.log(res.errMsg)
  570. }
  571. })
  572. },
  573. fail(res) {
  574. // 预登录失败
  575. // 不显示一键登录选项(或置灰)
  576. // 根据错误信息判断失败原因,如有需要可将错误提交给统计服务器
  577. console.log(res.errCode)
  578. console.log(res.errMsg)
  579. _this.onClickMsgLogin()
  580. uni.hideToast();
  581. uni.showToast({
  582. title: "请插入SIM卡并且使用流量后再重试",
  583. icon: "none",
  584. duration: 3000
  585. })
  586. }
  587. })
  588. },
  589. // 一键登录失败
  590. onClickMsgLogin() {
  591. uni.closeAuthView()
  592. uni.hideToast();
  593. setTimeout(() => {
  594. uni.showToast({
  595. title: "请插入SIM卡并且使用流量后再重试",
  596. icon: "none",
  597. duration: 3000
  598. })
  599. }, 500)
  600. }
  601. }
  602. }
  603. </script>
  604. <style scoped lang="scss">
  605. @import 'login.scss';
  606. </style>