index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <template>
  2. <div class="register absolute">
  3. <div class="shading">
  4. <div class="pictrue acea-row row-center-wrapper">
  5. <image :src="logoUrl" v-if="logoUrl" />
  6. </div>
  7. </div>
  8. <div class="whiteBg" v-if="formItem === 1">
  9. <div class="title acea-row row-center-wrapper">
  10. <div class="item" :class="current === index ? 'on' : ''" v-for="(item, index) in navList" @click="navTap(index)"
  11. :key="index">
  12. {{ item }}
  13. </div>
  14. </div>
  15. <div class="list" :hidden="current !== 0">
  16. <form @submit.prevent="submit">
  17. <div class="item">
  18. <div class="acea-row row-middle">
  19. <image src="/static/images/phone_1.png"></image>
  20. <input type="text" placeholder="输入手机号码" v-model="account" required />
  21. </div>
  22. </div>
  23. <div class="item">
  24. <div class="acea-row row-middle">
  25. <image src="/static/images/code_2.png"></image>
  26. <input type="password" placeholder="填写登录密码" v-model="password" required />
  27. </div>
  28. </div>
  29. </form>
  30. <navigator class="forgetPwd" hover-class="none" url="/pages/users/retrievePassword/index">
  31. <span class="iconfont icon-wenti"></span>忘记密码
  32. </navigator>
  33. </div>
  34. <div class="list" :hidden="current !== 1">
  35. <div class="item">
  36. <div class="acea-row row-middle">
  37. <image src="/static/images/phone_1.png"></image>
  38. <input type="text" placeholder="输入手机号码" v-model="account" />
  39. </div>
  40. </div>
  41. <div class="item">
  42. <div class="acea-row row-middle">
  43. <image src="/static/images/code_2.png"></image>
  44. <input type="text" placeholder="填写验证码" class="codeIput" v-model="captcha" />
  45. <button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">
  46. {{ text }}
  47. </button>
  48. </div>
  49. </div>
  50. <div class="item" v-if="isShowCode">
  51. <div class="acea-row row-middle">
  52. <image src="/static/images/code_2.png"></image>
  53. <input type="text" placeholder="填写验证码" class="codeIput" v-model="codeVal" />
  54. <div class="code" @click="again"><img :src="codeUrl" /></div>
  55. </div>
  56. </div>
  57. </div>
  58. <div class="logon" @click="loginMobile" :hidden="current !== 1">登录</div>
  59. <div class="logon" @click="submit" :hidden="current === 1">登录</div>
  60. <!-- <div class="tip">
  61. 没有账号?
  62. <span @click="formItem = 2" class="font-color-red">立即注册</span>
  63. </div> -->
  64. </div>
  65. <div class="whiteBg" v-else>
  66. <div class="title">注册账号</div>
  67. <div class="list">
  68. <div class="item">
  69. <div class="acea-row row-middle">
  70. <image src="/static/images/phone_1.png"></image>
  71. <input type="text" placeholder="输入手机号码" v-model="account" />
  72. </div>
  73. </div>
  74. <div class="item">
  75. <div class="acea-row row-middle">
  76. <image src="/static/images/code_2.png"></image>
  77. <input type="text" placeholder="填写验证码" class="codeIput" v-model="captcha" />
  78. <button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">
  79. {{ text }}
  80. </button>
  81. </div>
  82. </div>
  83. <div class="item">
  84. <div class="acea-row row-middle">
  85. <image src="/static/images/code_1.png"></image>
  86. <input type="password" placeholder="填写您的登录密码" v-model="password" />
  87. </div>
  88. </div>
  89. <div class="item" v-if="isShowCode">
  90. <div class="acea-row row-middle">
  91. <image src="/static/images/code_2.png"></image>
  92. <input type="text" placeholder="填写验证码" class="codeIput" v-model="codeVal" />
  93. <div class="code" @click="again"><img :src="codeUrl" /></div>
  94. </div>
  95. </div>
  96. </div>
  97. <div class="logon" @click="register">注册</div>
  98. <div class="tip">
  99. 已有账号?
  100. <span @click="formItem = 1" class="font-color-red">立即登录</span>
  101. </div>
  102. </div>
  103. <div class="bottom"></div>
  104. </div>
  105. </template>
  106. <script>
  107. import dayjs from "@/plugin/dayjs/dayjs.min.js";
  108. import sendVerifyCode from "@/mixins/SendVerifyCode";
  109. import {
  110. loginH5,
  111. loginMobile,
  112. registerVerify,
  113. register,
  114. getCodeApi,
  115. getUserInfo,
  116. getCaptcha
  117. } from "@/api/user";
  118. import attrs, {
  119. required,
  120. alpha_num,
  121. chs_phone
  122. } from "@/utils/validate";
  123. import {
  124. validatorDefaultCatch
  125. } from "@/utils/dialog";
  126. import {
  127. getLogo,
  128. getconfig
  129. } from "@/api/public";
  130. // import cookie from "@/utils/store/cookie";
  131. import {
  132. VUE_APP_API_URL
  133. } from "@/utils";
  134. const BACK_URL = "login_back_url";
  135. export default {
  136. name: "Login",
  137. mixins: [sendVerifyCode],
  138. data: function() {
  139. return {
  140. navList: ["账号登录", "注册/登录"],
  141. current: 1,
  142. account: "",
  143. password: "",
  144. captcha: "",
  145. formItem: 1,
  146. type: "login",
  147. logoUrl: "",
  148. keyCode: "",
  149. codeUrl: "",
  150. codeVal: "",
  151. isShowCode: false
  152. };
  153. },
  154. watch: {
  155. formItem: function(nval, oVal) {
  156. if (nval == 1) {
  157. this.type = 'login'
  158. } else {
  159. this.type = 'register'
  160. }
  161. }
  162. },
  163. onReady() {
  164. uni.$on('update', (data) => {
  165. this.logoUrl = data.login_logo
  166. console.log(this.logoUrl)
  167. })
  168. },
  169. mounted: function() {
  170. const app = getApp();
  171. this.$nextTick(() => {
  172. this.logoUrl = app.globalData.login_logo
  173. console.log(this.logoUrl)
  174. });
  175. },
  176. methods: {
  177. again() {
  178. // this.codeUrl =
  179. // VUE_APP_API_URL +
  180. // "/sms_captcha?" +
  181. // "key=" +
  182. // this.keyCode +
  183. // Date.parse(new Date());
  184. this.getcaptcha()
  185. },
  186. getCode() {
  187. let that = this
  188. getCodeApi()
  189. .then(res => {
  190. that.keyCode = res.data.key;
  191. })
  192. .catch(res => {
  193. that.$util.Tips({
  194. title: res
  195. });
  196. });
  197. },
  198. async getLogoImage() {
  199. let that = this;
  200. getLogo(2).then(res => {
  201. that.logoUrl = res.data.logo_url;
  202. });
  203. },
  204. async loginMobile() {
  205. let that = this;
  206. if (!that.account) return that.$util.Tips({
  207. title: '请输入手机号码'
  208. });
  209. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  210. title: '请输入正确的手机号码'
  211. });
  212. if (!that.captcha) return that.$util.Tips({
  213. title: '请输入验证码'
  214. });
  215. if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
  216. title: '请输入正确的验证码'
  217. });
  218. loginMobile({
  219. phone: that.account,
  220. sms_code: that.captcha,
  221. spread: that.$Cache.get("spread")
  222. })
  223. .then(({
  224. data
  225. }) => {
  226. const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  227. that.$Cache.clear(BACK_URL);
  228. that.$store.commit("LOGIN", {
  229. 'token': data.token,
  230. 'time': data.exp
  231. });
  232. that.$store.commit("SETUID", data.user.uid);
  233. that.$store.commit('UPDATE_USERINFO', data.user);
  234. let method
  235. let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart', '/pages/goods_cate/goods_cate',
  236. '/pages/user/index'
  237. ]
  238. if (indexPat.includes(this.getPath(backUrl))) {
  239. method = 'switchTab'
  240. } else {
  241. method = 'navigateTo'
  242. }
  243. if (this.getPath(backUrl) === '/pages/users/login/index') {
  244. uni.switchTab({
  245. url: '/pages/index/index'
  246. });
  247. return
  248. }
  249. uni[method]({
  250. url: backUrl
  251. });
  252. // if (backUrl === '/pages/index/index' || backUrl === '/pages/order_addcart/order_addcart' || backUrl ===
  253. // '/pages/user/index') {
  254. // uni.switchTab({
  255. // url: backUrl
  256. // });
  257. // } else {
  258. // uni.switchTab({
  259. // url: '/pages/index/index'
  260. // });
  261. // }
  262. })
  263. .catch(res => {
  264. that.$util.Tips({
  265. title: res
  266. });
  267. });
  268. },
  269. async register() {
  270. let that = this;
  271. if (!that.account) return that.$util.Tips({
  272. title: '请输入手机号码'
  273. });
  274. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  275. title: '请输入正确的手机号码'
  276. });
  277. if (!that.captcha) return that.$util.Tips({
  278. title: '请输入验证码'
  279. });
  280. if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
  281. title: '请输入正确的验证码'
  282. });
  283. if (!that.password) return that.$util.Tips({
  284. title: '请输入密码'
  285. });
  286. if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/i.test(that.password)) return that.$util.Tips({
  287. title: '您输入的密码过于简单'
  288. });
  289. register({
  290. account: that.account,
  291. captcha: that.captcha,
  292. password: that.password,
  293. spread: that.$Cache.get("spread")
  294. })
  295. .then(res => {
  296. that.$util.Tips({
  297. title: res
  298. });
  299. that.formItem = 1;
  300. })
  301. .catch(res => {
  302. that.$util.Tips({
  303. title: res
  304. });
  305. });
  306. },
  307. async code() {
  308. let that = this;
  309. if (!that.account) return that.$util.Tips({
  310. title: '请输入手机号码'
  311. });
  312. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  313. title: '请输入正确的手机号码'
  314. });
  315. // if (that.formItem == 2) that.type = "register";
  316. await registerVerify({
  317. phone: that.account,
  318. type: 'login',
  319. key: that.keyCode,
  320. code: that.codeVal
  321. })
  322. .then(res => {
  323. that.$util.Tips({
  324. title: res.message
  325. });
  326. that.sendCode();
  327. })
  328. .catch(res => {
  329. console.log(res, 'res22222222')
  330. that.getcaptcha();
  331. that.$util.Tips({
  332. title: res
  333. });
  334. });
  335. },
  336. getcaptcha() {
  337. let that = this
  338. getCaptcha().then(data => {
  339. // that.codeUrl = `${VUE_APP_API_URL}/sms_captcha?key=${that.keyCode}`;
  340. that.codeUrl = data.data.captcha;
  341. })
  342. that.isShowCode = true;
  343. },
  344. navTap: function(index) {
  345. this.current = index;
  346. },
  347. getPath(url) {
  348. if (url.indexOf("?") != -1) {
  349. url = url.split("?")[0];
  350. console.log(url);
  351. }
  352. return url
  353. },
  354. async submit() {
  355. let that = this;
  356. if (!that.account) return that.$util.Tips({
  357. title: '请输入账号'
  358. });
  359. if (!/^[\w\d]{5,16}$/i.test(that.account)) return that.$util.Tips({
  360. title: '请输入正确的账号'
  361. });
  362. if (!that.password) return that.$util.Tips({
  363. title: '请输入密码'
  364. });
  365. loginH5({
  366. account: that.account,
  367. password: that.password,
  368. spread: that.$Cache.get("spread")
  369. })
  370. .then(({
  371. data
  372. }) => {
  373. const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  374. that.$Cache.clear(BACK_URL);
  375. that.$store.commit("LOGIN", {
  376. 'token': data.token,
  377. 'time': data.exp
  378. });
  379. that.$store.commit("SETUID", data.user.uid);
  380. that.$store.commit('UPDATE_USERINFO', data.user);
  381. console.log(backUrl)
  382. console.log(this.getPath(backUrl))
  383. // if (backUrl) {
  384. // uni.navigateBack({
  385. // delta: 1
  386. // });
  387. // } else {
  388. // uni.switchTab({
  389. // url: '/pages/index/index'
  390. // });
  391. // }
  392. let method
  393. let indexPat = ['/pages/index/index', '/pages/order_addcart/order_addcart', '/pages/goods_cate/goods_cate',
  394. '/pages/user/index'
  395. ]
  396. if (indexPat.includes(this.getPath(backUrl))) {
  397. method = 'switchTab'
  398. } else {
  399. method = 'navigateTo'
  400. }
  401. if (this.getPath(backUrl) === '/pages/users/login/index') {
  402. uni.switchTab({
  403. url: '/pages/index/index'
  404. });
  405. return
  406. }
  407. uni[method]({
  408. url: backUrl
  409. });
  410. // if (backUrl === '/pages/index/index' || backUrl === '/pages/order_addcart/order_addcart' || backUrl ===
  411. // '/pages/user/index' || this.getPath(backUrl) === '/pages/columnGoods/goods_search_con/index') {
  412. // console.log('111')
  413. // if (this.getPath(backUrl) === '/pages/columnGoods/goods_search_con/index') {
  414. // uni.navigateTo({
  415. // url: backUrl
  416. // });
  417. // } else {
  418. // uni.switchTab({
  419. // url: backUrl
  420. // });
  421. // }
  422. // } else {
  423. // if (backUrl.split("?")[0] === '/pages/activity/assist_detail/index') {
  424. // uni.navigateTo({
  425. // url: backUrl
  426. // });
  427. // } else {
  428. // uni.switchTab({
  429. // url: '/pages/index/index'
  430. // });
  431. // }
  432. // }
  433. })
  434. .catch(e => {
  435. that.$util.Tips({
  436. title: e
  437. });
  438. });
  439. }
  440. }
  441. };
  442. </script>
  443. <style lang="scss">
  444. .code img {
  445. width: 100%;
  446. height: 100%;
  447. }
  448. .acea-row.row-middle {
  449. input {
  450. margin-left: 20rpx;
  451. }
  452. }
  453. </style>