index111.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <view class="register">
  3. <view class="shading">
  4. <view class="pictrue acea-row row-center-wrapper">
  5. <image :src="logoUrl" v-if="logoUrl"></image>
  6. <image src="/static/images/logo2.png" v-else></image>
  7. </view>
  8. </view>
  9. <view class="whiteBg" v-if="formItem === 1">
  10. <view class="title acea-row row-center-wrapper">
  11. <view class="item" :class="current === index ? 'on' : ''" v-for="(item, index) in navList" @click="navTap(index)"
  12. :key="index">
  13. {{ item }}
  14. </view>
  15. </view>
  16. <view class="list" :hidden="current !== 0">
  17. <form @submit.prevent="submit">
  18. <view class="item">
  19. <view class="acea-row row-middle">
  20. <image src="/static/images/phone_1.png"></image>
  21. <input type="text" placeholder="输入手机号码" v-model="account" placeholder-class="placeholder" class="input" />
  22. </view>
  23. </view>
  24. <view class="item">
  25. <view class="acea-row row-middle">
  26. <image src="/static/images/code_2.png"></image>
  27. <input type="password" placeholder="填写登录密码" v-model="password" placeholder-class="placeholder" class="input" />
  28. </view>
  29. </view>
  30. </form>
  31. <navigator url="/pages/retrieve_password/index" class="forgetPwd">
  32. <text class="iconfont icon-wenti"></text>忘记密码
  33. </navigator>
  34. </view>
  35. <view class="list" :hidden="current !== 1">
  36. <view class="item">
  37. <view class="acea-row row-middle">
  38. <image src="/static/images/phone_1.png"></image>
  39. <input type="text" placeholder="输入手机号码" placeholder-class="placeholder" class="input" v-model="account" />
  40. </view>
  41. </view>
  42. <view class="item">
  43. <view class="align-left acea-row row-middle">
  44. <image src="/static/images/code_2.png"></image>
  45. <input type="text" placeholder="填写验证码" class="codeIput" v-model="captcha" placeholder-class="placeholder" />
  46. <button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">
  47. {{ text }}
  48. </button>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="logon" @click="loginMobile" :hidden="current !== 1">登录</view>
  53. <view class="logon" @click="submit" :hidden="current === 1">登录</view>
  54. <view class="tip">
  55. 没有账号?
  56. <text @click="formItem = 2" class="font-color">立即注册</text>
  57. </view>
  58. </view>
  59. <view class="whiteBg" v-else>
  60. <view class="title">注册账号</view>
  61. <view class="list">
  62. <view class="item">
  63. <view class="acea-row row-middle">
  64. <image src="/static/images/phone_1.png"></image>
  65. <input type="text" placeholder="输入手机号码" placeholder-class="placeholder" class="input" v-model="account" />
  66. </view>
  67. </view>
  68. <view class="item">
  69. <view class="align-left acea-row row-middle">
  70. <image src="/static/images/code_2.png"></image>
  71. <input type="text" placeholder="填写验证码" class="codeIput" v-model="captcha" placeholder-class="placeholder" />
  72. <button class="code" :disabled="disabled" :class="disabled === true ? 'on' : ''" @click="code">
  73. {{ text }}
  74. </button>
  75. </view>
  76. </view>
  77. <view class="item">
  78. <view class="acea-row row-middle">
  79. <image src="/static/images/code_1.png"></image>
  80. <input type="password" placeholder="填写您的登录密码" placeholder-class="placeholder" class="input" v-model="password" />
  81. </view>
  82. </view>
  83. </view>
  84. <view class="logon" @click="register">注册</view>
  85. <view class="tip">
  86. 已有账号?
  87. <text @click="formItem = 1" class="font-color">立即登录</text>
  88. </view>
  89. </view>
  90. <view class="bottom"></view>
  91. </view>
  92. </template>
  93. <script>
  94. import sendVerifyCode from "@/mixins/SendVerifyCode";
  95. import {
  96. loginH5,
  97. loginMobile,
  98. registerVerify,
  99. register,
  100. getCodeApi,
  101. getUserInfo
  102. } from '@/api/user.js';
  103. import {
  104. getLogo
  105. } from "@/api/public";
  106. import dayjs from "dayjs";
  107. import {
  108. BACK_URL
  109. } from '@/config/cache';
  110. export default {
  111. mixins: [sendVerifyCode],
  112. data() {
  113. return {
  114. navList: ["账号登录", "快速登录"],
  115. current: 1,
  116. account: "",
  117. password: "",
  118. captcha: "",
  119. formItem: 1,
  120. type: "login",
  121. logoUrl: "",
  122. keyCode: "",
  123. }
  124. },
  125. onLoad() {
  126. this.getLogoImage();
  127. this.getCode();
  128. },
  129. methods: {
  130. // 获取keyCode
  131. getCode() {
  132. let that = this
  133. getCodeApi()
  134. .then(res => {
  135. this.keyCode = res.data.key;
  136. })
  137. .catch(res => {
  138. that.$util.Tips({title: res});
  139. });
  140. },
  141. getLogoImage() {
  142. let that = this;
  143. getLogo(2).then(res => {
  144. that.logoUrl = res.data.logo_url;
  145. });
  146. },
  147. loginMobile() {
  148. let that = this;
  149. if (!that.account) return that.$util.Tips({
  150. title: '请填写手机号码'
  151. });
  152. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  153. title: '请输入正确的手机号码'
  154. });
  155. if (!that.captcha) return that.$util.Tips({
  156. title: '请填写验证码'
  157. });
  158. if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
  159. title: '请输入正确的验证码'
  160. });
  161. loginMobile({
  162. phone: that.account,
  163. captcha: that.captcha,
  164. spread: that.$Cache.get("spread")
  165. })
  166. .then(res => {
  167. let data = res.data;
  168. let newTime = Math.round(new Date() / 1000);
  169. that.$store.commit("LOGIN", {
  170. 'token': data.token,
  171. 'time': dayjs(data.expires_time) - newTime
  172. });
  173. const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  174. that.$Cache.clear(BACK_URL);
  175. getUserInfo().then(res=>{
  176. that.$store.commit("SETUID", res.data.uid);
  177. if (backUrl === '/pages/index/index' || backUrl === '/pages/order_addcart/order_addcart' || backUrl ===
  178. '/pages/user/index' || backUrl === '/pages/goods_cate/goods_cate') {
  179. uni.switchTab({
  180. url: backUrl
  181. });
  182. } else {
  183. uni.redirectTo({
  184. url: backUrl
  185. });
  186. }
  187. })
  188. })
  189. .catch(res => {
  190. that.$util.Tips({
  191. title: res
  192. });
  193. });
  194. },
  195. register() {
  196. let that = this;
  197. if (!that.account) return that.$util.Tips({
  198. title: '请填写手机号码'
  199. });
  200. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  201. title: '请输入正确的手机号码'
  202. });
  203. if (!that.captcha) return that.$util.Tips({
  204. title: '请填写验证码'
  205. });
  206. if (!/^[\w\d]+$/i.test(that.captcha)) return that.$util.Tips({
  207. title: '请输入正确的验证码'
  208. });
  209. if (!that.password) return that.$util.Tips({
  210. title: '请填写密码'
  211. });
  212. if (!/^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$/i.test(that.password)) return that.$util.Tips({
  213. title: '您输入的密码过于简单'
  214. });
  215. register({
  216. account: that.account,
  217. captcha: that.captcha,
  218. password: that.password,
  219. spread: that.$Cache.get("spread")
  220. })
  221. .then(res => {
  222. that.$util.Tips({
  223. title: res.msg
  224. });
  225. that.formItem = 1;
  226. })
  227. .catch(res => {
  228. that.$util.Tips({
  229. title: res.msg
  230. });
  231. });
  232. },
  233. async code() {
  234. let that = this;
  235. if (!that.account) return that.$util.Tips({
  236. title: '请填写手机号码'
  237. });
  238. if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.account)) return that.$util.Tips({
  239. title: '请输入正确的手机号码'
  240. });
  241. if (that.formItem == 2) that.type = "register";
  242. await registerVerify({
  243. phone: that.account,
  244. type: that.type,
  245. key:that.keyCode,
  246. code:that.captcha
  247. })
  248. .then(res => {
  249. that.$util.Tips({
  250. title: res.msg
  251. });
  252. that.sendCode();
  253. })
  254. .catch(res => {
  255. that.$util.Tips({
  256. title: res
  257. });
  258. });
  259. },
  260. navTap: function(index) {
  261. this.current = index;
  262. },
  263. submit() {
  264. let that = this;
  265. if (!that.account) return that.$util.Tips({
  266. title: '请填写账号'
  267. });
  268. if (!/^[\w\d]{5,16}$/i.test(that.account)) return that.$util.Tips({
  269. title: '请输入正确的账号'
  270. });
  271. if (!that.password) return that.$util.Tips({
  272. title: '请填写密码'
  273. });
  274. // if (!/^[0-9A-Za-z]{6,16}$/i.test(that.password)) return that.$util.Tips({
  275. // title: '请输入正确的密码'
  276. // });
  277. loginH5({
  278. account: that.account,
  279. password: that.password
  280. })
  281. .then(({data}) => {
  282. let newTime = Math.round(new Date() / 1000);
  283. that.$store.commit("LOGIN", {
  284. 'token': data.token,
  285. 'time': dayjs(data.expires_time) - newTime
  286. });
  287. const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  288. that.$Cache.clear(BACK_URL);
  289. getUserInfo().then(res=>{
  290. that.$store.commit("SETUID", res.data.uid);
  291. if (backUrl === '/pages/index/index' || backUrl === '/pages/order_addcart/order_addcart' || backUrl ===
  292. '/pages/user/index' || backUrl === '/pages/goods_cate/goods_cate') {
  293. uni.switchTab({
  294. url: backUrl
  295. });
  296. } else {
  297. uni.redirectTo({
  298. url: backUrl
  299. });
  300. }
  301. })
  302. })
  303. .catch(e => {
  304. that.$util.Tips({
  305. title: e
  306. });
  307. });
  308. }
  309. }
  310. }
  311. </script>
  312. <style scoped lang="scss">
  313. </style>