login.vue 19 KB

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