login.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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: '注册日期:2024年5月',
  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: '',
  96. password: '',
  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. uni.navigateTo({
  165. url: '/pages/AboutUs/yszc'
  166. })
  167. } else {
  168. uni.navigateTo({
  169. url: page,
  170. });
  171. }
  172. },
  173. toRegist() {
  174. uni.navigateTo({
  175. url: "/pages/login/reg",
  176. });
  177. },
  178. toLogin() {
  179. console.log('aaa');
  180. let that = this;
  181. if (this.mobile.length != 11) {
  182. uni.showToast({
  183. title: "请输入手机号",
  184. icon: "none",
  185. });
  186. return;
  187. }
  188. if (this.type == 'pass') {
  189. if (this.password.length < 6) {
  190. uni.showToast({
  191. title: "请输入不小于6位的密码",
  192. icon: "none",
  193. });
  194. return;
  195. }
  196. } else {
  197. if (this.code.length < 4) {
  198. uni.showToast({
  199. title: "请输入手机验证码",
  200. icon: "none",
  201. });
  202. return;
  203. }
  204. }
  205. if (this.is_agree == 0) {
  206. uni.showToast({
  207. title: "请确认并选择协议",
  208. icon: "none",
  209. });
  210. return;
  211. }
  212. let method = '/Member/gamelogin';
  213. if (this.btn_type == 'reg') {
  214. method = '/Member/register';
  215. if (this.code.length < 4) {
  216. uni.showToast({
  217. title: '请输入验证码',
  218. icon: 'none'
  219. });
  220. return;
  221. }
  222. } else if (this.btn_type == 'reset') {
  223. method = '/Member/resetPass';
  224. if (this.code.length < 4) {
  225. uni.showToast({
  226. title: '请输入验证码',
  227. icon: 'none'
  228. });
  229. return;
  230. }
  231. }
  232. let channel = "";
  233. // #ifdef APP-PLUS
  234. channel = plus.runtime.channel;
  235. // #endif
  236. uni.showLoading({
  237. mask: true,
  238. });
  239. console.log("host", this.$apiHost + method);
  240. uni.request({
  241. url: this.$apiHost + method,
  242. data: {
  243. uuid: getApp().globalData.uuid,
  244. channel: channel,
  245. loginType: this.type,
  246. mobile: this.mobile,
  247. password: this.password,
  248. code: this.code,
  249. push_token: this.push_token,
  250. lat: this.lat,
  251. lng: this.lng,
  252. },
  253. header: {
  254. "content-type": "application/json",
  255. },
  256. success: (res) => {
  257. console.log("----", res.data);
  258. if (res.data.success == "yes") {
  259. console.log("res.data", res.data);
  260. uni.setStorageSync("wapptoken", res.data.skey);
  261. getApp().globalData.skey = res.data.skey;
  262. if (res.data.header_c != "") {
  263. getApp().globalData.headerSign = pubc.Encrypt(res.data.header_c + "_" +
  264. getApp().globalData.uuid);
  265. uni.setStorageSync("headerSign", getApp().globalData.headerSign);
  266. }
  267. getApp().globalData.headerC = res.data.header_c;
  268. if (res.data.nickname == '') {
  269. uni.redirectTo({
  270. url: '/pages/my/step'
  271. });
  272. return;
  273. }
  274. uni.switchTab({
  275. url: "/pages/index/index",
  276. });
  277. } else if (res.data.success == "no") {
  278. uni.showToast({
  279. title: res.data.str,
  280. icon: "none",
  281. });
  282. } else {
  283. uni.showToast({
  284. title: "操作失败,请联系客服",
  285. icon: "none",
  286. });
  287. }
  288. },
  289. complete: (com) => {
  290. uni.hideLoading();
  291. },
  292. });
  293. },
  294. getCode() {
  295. if (this.mobile.length != 11) {
  296. uni.showToast({
  297. title: '请输入手机号',
  298. icon: 'none'
  299. });
  300. return;
  301. }
  302. if (this.captchaTime > 0) {
  303. uni.showToast({
  304. title: '不能重复获取',
  305. icon: 'none'
  306. });
  307. return;
  308. }
  309. this.captchaTime = 60;
  310. uni.request({
  311. url: this.$apiHost + '/Web/getcode', //仅为示例,并非真实接口地址。
  312. data: {
  313. skey: this.skey,
  314. mobile: this.mobile,
  315. },
  316. header: {
  317. 'content-type': 'application/json' //自定义请求头信息
  318. },
  319. success: (res) => {
  320. console.log("----", res.data)
  321. uni.showToast({
  322. title: res.data.str,
  323. icon: 'none'
  324. })
  325. if (res.data.success == 'yes') {
  326. this.getCodeTime();
  327. } else {
  328. this.captchaTime = 0;
  329. }
  330. }
  331. });
  332. },
  333. }
  334. }
  335. </script>
  336. <style scoped lang="scss">
  337. @import 'login.scss';
  338. </style>