login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  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="number" 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" v-if="false">
  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="goWeb('https://e.zhichao.art/web/yszc.php', '隐私协议')">
  63. 隐私协议
  64. </text>
  65. 》和《
  66. <text class="xy" @click="goWeb('https://e.zhichao.art/web/yhxy.php', '用户使用协议')">
  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: '',
  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: '',
  98. password: '',
  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. goWeb(url, title) {
  153. uni.navigateTo({
  154. url: `/pages/webview/index?url=${encodeURIComponent(url)}&title=${encodeURIComponent(title) }`
  155. })
  156. },
  157. onBack() { },
  158. agreeChk() {
  159. if (this.is_agree == 0) {
  160. this.is_agree = 1;
  161. } else {
  162. this.is_agree = 0;
  163. }
  164. },
  165. goPage(page) {
  166. if (page == 'yhxy') {
  167. uni.navigateTo({
  168. url: '/pages/AboutUs/yhxy'
  169. })
  170. } else if (page == 'yszc') {
  171. // #ifdef APP-PLUS
  172. plus.runtime.openWeb('https://e.zhichao.art/web/yszc.php') // plus.runtime.openWeb(href);
  173. // #endif
  174. // #ifdef H5
  175. window.open('https://e.zhichao.art/web/yszc.php')
  176. // #endif
  177. // uni.navigateTo({
  178. // url: '/pages/AboutUs/yszc'
  179. // })
  180. } else {
  181. uni.navigateTo({
  182. url: page,
  183. });
  184. }
  185. },
  186. toRegist() {
  187. uni.navigateTo({
  188. url: "/pages/login/reg",
  189. });
  190. },
  191. toLogin() {
  192. console.log('aaa');
  193. let that = this;
  194. if (this.mobile.length != 11) {
  195. uni.showToast({
  196. title: "请输入手机号",
  197. icon: "none",
  198. });
  199. return;
  200. }
  201. if (this.type == 'pass') {
  202. if (this.password.length < 6) {
  203. uni.showToast({
  204. title: "请输入不小于6位的密码",
  205. icon: "none",
  206. });
  207. return;
  208. }
  209. } else {
  210. if (this.code.length < 4) {
  211. uni.showToast({
  212. title: "请输入手机验证码",
  213. icon: "none",
  214. });
  215. return;
  216. }
  217. }
  218. if (this.is_agree == 0) {
  219. uni.showToast({
  220. title: "请确认并选择协议",
  221. icon: "none",
  222. });
  223. return;
  224. }
  225. let method = '/Member/gamelogin';
  226. if (this.btn_type == 'reg') {
  227. method = '/Member/register';
  228. if (this.code.length < 4) {
  229. uni.showToast({
  230. title: '请输入验证码',
  231. icon: 'none'
  232. });
  233. return;
  234. }
  235. } else if (this.btn_type == 'reset') {
  236. method = '/Member/resetPass';
  237. if (this.code.length < 4) {
  238. uni.showToast({
  239. title: '请输入验证码',
  240. icon: 'none'
  241. });
  242. return;
  243. }
  244. }
  245. let channel = "";
  246. // #ifdef APP-PLUS
  247. channel = plus.runtime.channel;
  248. // #endif
  249. uni.showLoading({
  250. mask: true,
  251. });
  252. console.log("host", this.$apiHost + method);
  253. uni.request({
  254. url: this.$apiHost + method,
  255. data: {
  256. uuid: getApp().globalData.uuid,
  257. channel: channel,
  258. loginType: this.type,
  259. mobile: this.mobile,
  260. password: this.password,
  261. code: this.code,
  262. push_token: this.push_token,
  263. lat: this.lat,
  264. lng: this.lng,
  265. },
  266. header: {
  267. "content-type": "application/json",
  268. },
  269. success: (res) => {
  270. console.log("----", res.data);
  271. if (res.data.success == "yes") {
  272. console.log("res.data", res.data);
  273. if (res.data.uuid.length > 5) {
  274. uni.setStorageSync("app_uuid", res.data.uuid);
  275. getApp().globalData.uuid = res.data.uuid;
  276. }
  277. uni.setStorageSync("is_login", "yes");
  278. uni.setStorageSync("wapptoken", res.data.skey);
  279. getApp().globalData.skey = res.data.skey;
  280. if (res.data.header_c != "") {
  281. getApp().globalData.headerSign = pubc.Encrypt(res.data.header_c + "_" +
  282. getApp().globalData.uuid);
  283. uni.setStorageSync("headerSign", getApp().globalData.headerSign);
  284. }
  285. getApp().globalData.headerC = res.data.header_c;
  286. if (res.data.nickname == '') {
  287. uni.redirectTo({
  288. url: '/pages/my/step'
  289. });
  290. return;
  291. }
  292. // 获取用户信息储存全局
  293. uni.request({
  294. url: this.$apiHost + '/User/getinfo',
  295. data: {
  296. uuid: getApp().globalData.uuid,
  297. skey: getApp().globalData.skey
  298. },
  299. header: {
  300. "content-type": "application/json",
  301. 'sign': getApp().globalData.headerSign
  302. },
  303. success: (res) => {
  304. console.log("--获取用户信息--:", res.data);
  305. if (res.data.need_login == "yes") {
  306. }
  307. if (res.data.aihao) {
  308. this.aihao_tags = res.data.aihao.split(",");
  309. }
  310. if (res.data.nickname) {
  311. getApp().globalData.nickname = res.data.nickname
  312. uni.removeStorageSync("nickname");
  313. uni.setStorageSync("nickname", res.data.nickname);
  314. }
  315. if (res.data.mobile) {
  316. getApp().globalData.mobile = res.data.mobile
  317. uni.removeStorageSync("mobile", res.data.mobile);
  318. uni.setStorageSync("mobile", res.data.mobile);
  319. }
  320. if (res.data.user_id) {
  321. getApp().globalData.user_id = res.data.user_id
  322. uni.removeStorageSync("user_id");
  323. uni.setStorageSync("user_id", res.data.user_id);
  324. }
  325. if (res.data.avator) {
  326. getApp().globalData.avator = res.data.avator
  327. uni.removeStorageSync("avator");
  328. uni.setStorageSync("avator", res.data.avator);
  329. }
  330. },
  331. complete: (com) => {
  332. // uni.hideLoading();
  333. },
  334. fail: (e) => {
  335. console.log("----e:", e);
  336. }
  337. });
  338. uni.switchTab({
  339. url: "/pages/index/index",
  340. });
  341. } else if (res.data.success == "no") {
  342. uni.showToast({
  343. title: res.data.str,
  344. icon: "none",
  345. });
  346. } else {
  347. uni.showToast({
  348. title: "操作失败,请联系客服",
  349. icon: "none",
  350. });
  351. }
  352. },
  353. complete: (com) => {
  354. uni.hideLoading();
  355. },
  356. });
  357. },
  358. getCode() {
  359. if (this.mobile.length != 11) {
  360. uni.showToast({
  361. title: '请输入手机号',
  362. icon: 'none'
  363. });
  364. return;
  365. }
  366. if (this.captchaTime > 0) {
  367. uni.showToast({
  368. title: '不能重复获取',
  369. icon: 'none'
  370. });
  371. return;
  372. }
  373. this.captchaTime = 60;
  374. uni.request({
  375. url: this.$apiHost + '/Web/getcode', //仅为示例,并非真实接口地址。
  376. data: {
  377. skey: this.skey,
  378. mobile: this.mobile,
  379. },
  380. header: {
  381. 'content-type': 'application/json' //自定义请求头信息
  382. },
  383. success: (res) => {
  384. console.log("----", res.data)
  385. uni.showToast({
  386. title: res.data.str,
  387. icon: 'none'
  388. })
  389. if (res.data.success == 'yes') {
  390. this.getCodeTime();
  391. } else {
  392. this.captchaTime = 0;
  393. }
  394. }
  395. });
  396. },
  397. getCodeTime() {
  398. if (this.captchaTime > 0) {
  399. setTimeout(() => {
  400. this.captchaTime--;
  401. this.getCodeTime();
  402. }, 1000);
  403. }
  404. }
  405. }
  406. }
  407. </script>
  408. <style scoped lang="scss">
  409. @import 'login.scss';
  410. </style>