login - copy.vue 10 KB

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