login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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. <block v-if="type == 'onelogin'">
  12. <image class="icon" mode="widthFix" src="../../static/me/avator.png"></image>
  13. <text class="mobile">+ 86 1**********</text>
  14. <text class="tips">首次验证通过即注册萌创星球账号</text>
  15. <text class="btn_submit">本机号码一键登录</text>
  16. <view class="other">
  17. <view class="pass" @click="type = 'pass'">密码登录</view>
  18. <view class="line"></view>
  19. <view class="mob" @click="type = 'mobile'">手机号登录</view>
  20. </view>
  21. </block>
  22. <block v-if="type == 'pass' || type == 'mobile'">
  23. <view class="name">手机号码:</view>
  24. <view class="item">
  25. <input type="text" class="input" v-model="mobile" placeholder="请输入手机号码" maxlength="11" />
  26. </view>
  27. <block v-if="type == 'pass'">
  28. <view class="name">登录密码:</view>
  29. <view class="item">
  30. <input type="password" class="input" v-model="password" placeholder="请输入登录密码" maxlength="32" />
  31. </view>
  32. <view class="other_list">
  33. <text class="left" v-if="true" @click="type = 'mobile'">验证码登录</text>
  34. <text class="left" v-else></text>
  35. <text class="right" @click="type = 'mobile'" v-if="false">验证码登录</text>
  36. <text class="right" @click="toRegist">还没有账号?开始注册</text>
  37. </view>
  38. </block>
  39. <block v-if="type == 'mobile'">
  40. <view class="name">验证码:</view>
  41. <view class="item">
  42. <input type="text" class="input" v-model="code" placeholder="请输入验证码" maxlength="6" />
  43. <view class="btn" v-if="captchaTime === 0" @click="getCode">获取验证码</view>
  44. <view class="btn" v-if="captchaTime > 0">{{ captchaTime }}秒后重试</view>
  45. </view>
  46. <view class="other_list">
  47. <text class="left"></text>
  48. <text class="right" @click="type = 'pass'" style="color: blue;">密码登录</text>
  49. </view>
  50. </block>
  51. <text class="btn_submit" @click="toLogin">登录/注册</text>
  52. </block>
  53. <view class="wechat" v-if="false">
  54. <image class="img" mode="widthFix" src="../../static/login/wechat.png"></image>
  55. </view>
  56. <view class="agree">
  57. <view class="agree2" @click="agreeChk()">
  58. <image mode="widthFix" src="../../static/icon/wd_icon_gouxuan04.png" v-if="is_agree == 0"></image>
  59. <image mode="widthFix" src="../../static/icon/wd_icon_gouxuan05.png" v-if="is_agree == 1"></image>
  60. <text>我已阅读并同意</text>
  61. </view>
  62. <text class="xy" @click="goPage('yhxy')">
  63. 隐私协议
  64. </text>
  65. 》和《
  66. <text class="xy" @click="goPage('yszc')">
  67. 用户使用协议
  68. </text>
  69. </view>
  70. <view class="agree" v-if="false"><text class="agree2">{{ push_token }}</text></view>
  71. </view>
  72. <view class="blankHeight"></view>
  73. <DialogBox ref="DialogBox"></DialogBox>
  74. </view>
  75. </template>
  76. <script>
  77. import pubc from '@/common/public.js'
  78. export default {
  79. components: {},
  80. data() {
  81. return {
  82. skey: '',
  83. sel: 1,
  84. is_agree: 0,
  85. type: 'mobile',
  86. myinfo: {
  87. nickname: '王思思',
  88. join_name: '注册日期:2024年5月',
  89. num_1: 0,
  90. num_2: 0,
  91. num_3: 0,
  92. num_4: 0,
  93. is_login: 'no',
  94. num_history: 0,
  95. num_collection: 0
  96. },
  97. mobile: '18899990000',
  98. password: '111111',
  99. code: '',
  100. captchaTime: 0,
  101. push_token: '',
  102. lat: '',
  103. lng: '',
  104. }
  105. },
  106. onLoad() {
  107. setTimeout(function () {
  108. uni.setNavigationBarColor({
  109. frontColor: '#ffffff',
  110. backgroundColor: '#00000000',
  111. animation: {
  112. duration: 400,
  113. timingFunc: 'easeIn'
  114. }
  115. })
  116. }, 200);
  117. let that = this;
  118. uni.getPushClientId({
  119. success: (res) => {
  120. console.log("su:", res.cid);
  121. that.push_token = res.cid;
  122. },
  123. fail(err) {
  124. that.push_token = '';
  125. console.log(err)
  126. }
  127. });
  128. },
  129. onShow() {
  130. // let hsign = pubc.Encrypt("aboa-wifl-kwfl-zjfk-wlaa_FA0412932BAE9D98506580ADB348BEF9");
  131. // console.log("hsign", hsign)
  132. // let skey = uni.getStorageSync("wapptoken");
  133. // if (skey != null && skey != "" && skey != undefined) {
  134. // uni.switchTab({
  135. // url: "/pages/index/index"
  136. // });
  137. // return;
  138. // }
  139. // let that = this;
  140. // uni.getLocation({
  141. // type: 'wgs84',
  142. // success: function(res) {
  143. // that.lat = res.latitude;
  144. // that.lng = res.longitude;
  145. // },
  146. // fail: function(error) {
  147. // console.error('获取位置失败:', error);
  148. // }
  149. // });
  150. },
  151. methods: {
  152. onBack() { },
  153. agreeChk() {
  154. if (this.is_agree == 0) {
  155. this.is_agree = 1;
  156. } else {
  157. this.is_agree = 0;
  158. }
  159. },
  160. goPage(page) {
  161. if (page == 'yhxy') {
  162. uni.navigateTo({
  163. url: '/pages/AboutUs/yhxy'
  164. })
  165. } else if (page == 'yszc') {
  166. // #ifdef APP-PLUS
  167. plus.runtime.openWeb('https://e.zhichao.art/web/yszc.php') // plus.runtime.openWeb(href);
  168. // #endif
  169. // #ifdef H5
  170. window.open('https://e.zhichao.art/web/yszc.php')
  171. // #endif
  172. // uni.navigateTo({
  173. // url: '/pages/AboutUs/yszc'
  174. // })
  175. } else {
  176. uni.navigateTo({
  177. url: page,
  178. });
  179. }
  180. },
  181. toRegist() {
  182. uni.navigateTo({
  183. url: "/pages/login/reg",
  184. });
  185. },
  186. toLogin() {
  187. console.log('aaa');
  188. let that = this;
  189. if (this.mobile.length != 11) {
  190. uni.showToast({
  191. title: "请输入手机号",
  192. icon: "none",
  193. });
  194. return;
  195. }
  196. if (this.type == 'pass') {
  197. if (this.password.length < 6) {
  198. uni.showToast({
  199. title: "请输入不小于6位的密码",
  200. icon: "none",
  201. });
  202. return;
  203. }
  204. } else {
  205. if (this.code.length < 4) {
  206. uni.showToast({
  207. title: "请输入手机验证码",
  208. icon: "none",
  209. });
  210. return;
  211. }
  212. }
  213. if (this.is_agree == 0) {
  214. uni.showToast({
  215. title: "请确认并选择协议",
  216. icon: "none",
  217. });
  218. return;
  219. }
  220. let method = '/Member/gamelogin';
  221. if (this.btn_type == 'reg') {
  222. method = '/Member/register';
  223. if (this.code.length < 4) {
  224. uni.showToast({
  225. title: '请输入验证码',
  226. icon: 'none'
  227. });
  228. return;
  229. }
  230. } else if (this.btn_type == 'reset') {
  231. method = '/Member/resetPass';
  232. if (this.code.length < 4) {
  233. uni.showToast({
  234. title: '请输入验证码',
  235. icon: 'none'
  236. });
  237. return;
  238. }
  239. }
  240. let channel = "";
  241. // #ifdef APP-PLUS
  242. channel = plus.runtime.channel;
  243. // #endif
  244. uni.showLoading({
  245. mask: true,
  246. });
  247. console.log("host", this.$apiHost + method);
  248. uni.request({
  249. url: this.$apiHost + method,
  250. data: {
  251. uuid: getApp().globalData.uuid,
  252. channel: channel,
  253. loginType: this.type,
  254. mobile: this.mobile,
  255. password: this.password,
  256. code: this.code,
  257. push_token: this.push_token,
  258. lat: this.lat,
  259. lng: this.lng,
  260. },
  261. header: {
  262. "content-type": "application/json",
  263. },
  264. success: (res) => {
  265. console.log("----", res.data);
  266. if (res.data.success == "yes") {
  267. console.log("res.data", res.data);
  268. if (res.data.uuid.length > 5) {
  269. uni.setStorageSync("app_uuid", res.data.uuid);
  270. getApp().globalData.uuid = res.data.uuid;
  271. }
  272. uni.setStorageSync("is_login", "yes");
  273. uni.setStorageSync("wapptoken", res.data.skey);
  274. getApp().globalData.skey = res.data.skey;
  275. if (res.data.header_c != "") {
  276. getApp().globalData.headerSign = pubc.Encrypt(res.data.header_c + "_" +
  277. getApp().globalData.uuid);
  278. uni.setStorageSync("headerSign", getApp().globalData.headerSign);
  279. }
  280. getApp().globalData.headerC = res.data.header_c;
  281. if (res.data.nickname == '') {
  282. uni.redirectTo({
  283. url: '/pages/my/step'
  284. });
  285. return;
  286. }
  287. // 获取用户信息储存全局
  288. uni.request({
  289. url: this.$apiHost + '/User/getinfo',
  290. data: {
  291. uuid: getApp().globalData.uuid,
  292. skey: getApp().globalData.skey
  293. },
  294. header: {
  295. "content-type": "application/json",
  296. 'sign': getApp().globalData.headerSign
  297. },
  298. success: (res) => {
  299. console.log("--获取用户信息--:", res.data);
  300. if (res.data.need_login == "yes") {
  301. }
  302. if (res.data.aihao) {
  303. this.aihao_tags = res.data.aihao.split(",");
  304. }
  305. if (res.data.nickname) {
  306. getApp().globalData.nickname = res.data.nickname
  307. uni.removeStorageSync("nickname" );
  308. uni.setStorageSync("nickname", res.data.nickname);
  309. }
  310. if (res.data.mobile) {
  311. getApp().globalData.mobile = res.data.mobile
  312. uni.removeStorageSync("mobile", res.data.mobile);
  313. uni.setStorageSync("mobile", res.data.mobile);
  314. }
  315. if (res.data.user_id) {
  316. getApp().globalData.user_id = res.data.user_id
  317. uni.removeStorageSync("user_id" );
  318. uni.setStorageSync("user_id", res.data.user_id);
  319. }
  320. if (res.data.avator) {
  321. getApp().globalData.avator = res.data.avator
  322. uni.removeStorageSync("avator" );
  323. uni.setStorageSync("avator", res.data.avator);
  324. }
  325. },
  326. complete: (com) => {
  327. // uni.hideLoading();
  328. },
  329. fail: (e) => {
  330. console.log("----e:", e);
  331. }
  332. });
  333. uni.switchTab({
  334. url: "/pages/index/index",
  335. });
  336. } else if (res.data.success == "no") {
  337. uni.showToast({
  338. title: res.data.str,
  339. icon: "none",
  340. });
  341. } else {
  342. uni.showToast({
  343. title: "操作失败,请联系客服",
  344. icon: "none",
  345. });
  346. }
  347. },
  348. complete: (com) => {
  349. uni.hideLoading();
  350. },
  351. });
  352. },
  353. getCode() {
  354. if (this.mobile.length != 11) {
  355. uni.showToast({
  356. title: '请输入手机号',
  357. icon: 'none'
  358. });
  359. return;
  360. }
  361. if (this.captchaTime > 0) {
  362. uni.showToast({
  363. title: '不能重复获取',
  364. icon: 'none'
  365. });
  366. return;
  367. }
  368. this.captchaTime = 60;
  369. uni.request({
  370. url: this.$apiHost + '/Web/getcode', //仅为示例,并非真实接口地址。
  371. data: {
  372. skey: this.skey,
  373. mobile: this.mobile,
  374. },
  375. header: {
  376. 'content-type': 'application/json' //自定义请求头信息
  377. },
  378. success: (res) => {
  379. console.log("----", res.data)
  380. uni.showToast({
  381. title: res.data.str,
  382. icon: 'none'
  383. })
  384. if (res.data.success == 'yes') {
  385. this.getCodeTime();
  386. } else {
  387. this.captchaTime = 0;
  388. }
  389. }
  390. });
  391. },
  392. getCodeTime() {
  393. if (this.captchaTime > 0) {
  394. setTimeout(() => {
  395. this.captchaTime--;
  396. this.getCodeTime();
  397. }, 1000);
  398. }
  399. }
  400. }
  401. }
  402. </script>
  403. <style scoped lang="scss">
  404. @import 'login.scss';
  405. </style>