login.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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="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": false, // 是否全屏显示,默认值: 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. uni.showToast({
  364. title: "登录成功",
  365. icon: "none",
  366. });
  367. console.log("res.data", res.data);
  368. if (res.data.uuid.length > 5) {
  369. uni.setStorageSync("app_uuid", res.data.uuid);
  370. getApp().globalData.uuid = res.data.uuid;
  371. }
  372. uni.setStorageSync("is_login", "yes");
  373. uni.setStorageSync("wapptoken", res.data.skey);
  374. getApp().globalData.skey = res.data.skey;
  375. if (res.data.header_c != "") {
  376. getApp().globalData.headerSign = pubc.Encrypt(res.data.header_c + "_" +
  377. getApp().globalData.uuid);
  378. uni.setStorageSync("headerSign", getApp().globalData.headerSign);
  379. }
  380. getApp().globalData.headerC = res.data.header_c;
  381. if (res.data.nickname == '') {
  382. uni.redirectTo({
  383. url: '/pages/my/step'
  384. });
  385. return;
  386. }
  387. // 获取用户信息储存全局
  388. uni.request({
  389. url: this.$apiHost + '/User/getinfo',
  390. data: {
  391. uuid: getApp().globalData.uuid,
  392. skey: getApp().globalData.skey
  393. },
  394. header: {
  395. "content-type": "application/json",
  396. 'sign': getApp().globalData.headerSign
  397. },
  398. success: (res) => {
  399. console.log("--获取用户信息--:", res.data);
  400. if (res.data.need_login == "yes") {
  401. }
  402. if (res.data.aihao) {
  403. this.aihao_tags = res.data.aihao.split(",");
  404. }
  405. if (res.data.nickname) {
  406. getApp().globalData.nickname = res.data.nickname
  407. uni.removeStorageSync("nickname");
  408. uni.setStorageSync("nickname", res.data.nickname);
  409. }
  410. if (res.data.mobile) {
  411. getApp().globalData.mobile = res.data.mobile
  412. uni.removeStorageSync("mobile", res.data.mobile);
  413. uni.setStorageSync("mobile", res.data.mobile);
  414. }
  415. if (res.data.user_id) {
  416. getApp().globalData.user_id = res.data.user_id
  417. uni.removeStorageSync("user_id");
  418. uni.setStorageSync("user_id", res.data.user_id);
  419. }
  420. if (res.data.avator) {
  421. getApp().globalData.avator = res.data.avator
  422. uni.removeStorageSync("avator");
  423. uni.setStorageSync("avator", res.data.avator);
  424. }
  425. },
  426. complete: (com) => {
  427. // uni.hideLoading();
  428. },
  429. fail: (e) => {
  430. console.log("----e:", e);
  431. }
  432. });
  433. uni.switchTab({
  434. url: "/pages/index/index",
  435. });
  436. } else if (res.data.success == "no") {
  437. uni.showToast({
  438. title: res.data.str,
  439. icon: "none",
  440. });
  441. } else {
  442. uni.showToast({
  443. title: "操作失败,请联系客服",
  444. icon: "none",
  445. });
  446. }
  447. },
  448. complete: (com) => {
  449. uni.hideLoading();
  450. },
  451. });
  452. },
  453. getCode() {
  454. if (this.mobile.length != 11) {
  455. uni.showToast({
  456. title: '请输入手机号',
  457. icon: 'none'
  458. });
  459. return;
  460. }
  461. if (this.captchaTime > 0) {
  462. uni.showToast({
  463. title: '不能重复获取',
  464. icon: 'none'
  465. });
  466. return;
  467. }
  468. this.captchaTime = 60;
  469. uni.request({
  470. url: this.$apiHost + '/Web/getcode', //仅为示例,并非真实接口地址。
  471. data: {
  472. skey: this.skey,
  473. mobile: this.mobile,
  474. },
  475. header: {
  476. 'content-type': 'application/json' //自定义请求头信息
  477. },
  478. success: (res) => {
  479. console.log("----", res.data)
  480. uni.showToast({
  481. title: res.data.str,
  482. icon: 'none'
  483. })
  484. if (res.data.success == 'yes') {
  485. this.getCodeTime();
  486. } else {
  487. this.captchaTime = 0;
  488. }
  489. }
  490. });
  491. },
  492. getCodeTime() {
  493. if (this.captchaTime > 0) {
  494. setTimeout(() => {
  495. this.captchaTime--;
  496. this.getCodeTime();
  497. }, 1000);
  498. }
  499. },
  500. oneClickLoginFun() {
  501. let _this = this;
  502. //预登陆
  503. uni.preLogin({
  504. provider: 'univerify',
  505. success() { //预登录成功
  506. // 显示一键登录选项
  507. uni.login({
  508. provider: 'univerify',
  509. univerifyStyle: _this.univerifyStyle,
  510. success(res) { // 登录成功
  511. console.log(res.authResult.access_token);
  512. console.log(res.authResult.openid);
  513. // 此处获取了openid和access_token
  514. // {openid:'登录授权唯一标识',access_token:'接口返回的 token'}
  515. // 通过uniCloud.callFunction函数实现前端获取手机号
  516. uniCloud.callFunction({
  517. name: "oneClickLogin", // 填写你自己的云函数名称
  518. //传入上面获取的openid和access_token获取手机号
  519. data: {
  520. access_token: res.authResult.access_token, // 客户端一键登录接口返回的access_token
  521. openid: res.authResult.openid // 客户端一键登录接口返回的openid
  522. }
  523. }).then((dataRes) => {
  524. //此处已经成功获取手机号等信息
  525. console.log("云函数返回的参数1", dataRes)
  526. let phone = dataRes.result.data.phoneNumber
  527. if (phone) {
  528. _this.loginInterface({
  529. isOneClickLogin: true,
  530. phone,
  531. })
  532. setTimeout(() => {
  533. uni.closeAuthView() //关闭一键登录弹出窗口
  534. }, 500)
  535. } else {
  536. }
  537. // 获取手机号后根据自己的需求做后面的登录操作即可
  538. //...
  539. }).catch((err) => {
  540. console.log(err);
  541. console.log("云函数报错", err)
  542. uni.showToast({
  543. title: err.errMsg,
  544. icon: "none"
  545. })
  546. this_ = this
  547. setTimeout(() => {
  548. uni.closeAuthView() //关闭一键登录弹出窗口
  549. _this.onClickMsgLogin()
  550. uni.showToast({
  551. title: "请插入SIM卡并且使用流量后再重试",
  552. icon: "none"
  553. })
  554. }, 500)
  555. })
  556. },
  557. fail(res) { // 登录失败
  558. console.log(res.errCode)
  559. console.log(res.errMsg)
  560. }
  561. })
  562. },
  563. fail(res) {
  564. // 预登录失败
  565. // 不显示一键登录选项(或置灰)
  566. // 根据错误信息判断失败原因,如有需要可将错误提交给统计服务器
  567. console.log(res.errCode)
  568. console.log(res.errMsg)
  569. _this.onClickMsgLogin()
  570. uni.hideToast();
  571. uni.showToast({
  572. title: "请插入SIM卡并且使用流量后再重试",
  573. icon: "none",
  574. duration: 3000
  575. })
  576. }
  577. })
  578. },
  579. // 一键登录失败
  580. onClickMsgLogin() {
  581. uni.closeAuthView()
  582. uni.hideToast();
  583. setTimeout(() => {
  584. uni.showToast({
  585. title: "请插入SIM卡并且使用流量后再重试",
  586. icon: "none",
  587. duration: 3000
  588. })
  589. }, 500)
  590. }
  591. }
  592. }
  593. </script>
  594. <style scoped lang="scss">
  595. @import 'login.scss';
  596. </style>