login.vue 18 KB

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