login.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <view class="register">
  3. <view class="content">
  4. <!-- 头部logo -->
  5. <view class="header">
  6. <image src="https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/loginlogo.png"></image>
  7. </view>
  8. <!-- 主体 -->
  9. <view class="main">
  10. <wInput v-model="phoneData" type="text" maxlength="11" placeholder="手机号"></wInput>
  11. <wInput v-model="verCode" type="number" maxlength="6" placeholder="验证码" isShowCode ref="runCode" @setCode="getVerCode()"></wInput>
  12. </view>
  13. <wButton class="wbutton" text="登 录" :rotate="isRotate" @click.native="startReg()" bgColor="linear-gradient(to right, rgba(11,115,185,0.7), rgba(11,115,185,0.6))"></wButton>
  14. <view class="flex justify-between align-center" style="margin-top: 60rpx;">
  15. <button v-if="!isphoneNum" style="margin-top: 20rpx;" :class="['buttonBorder',!istrue?'dlbutton':'dlbutton_loading']"
  16. open-type="getPhoneNumber" @getphonenumber="getphone">
  17. <view :class="istrue?'rotate_loop':''">
  18. <text v-if="istrue" class="cuIcon cuIcon-loading1"></text>
  19. <view v-if="!istrue">
  20. <slot name="text">微信授权一键登录</slot>
  21. </view>
  22. </view>
  23. </button>
  24. <button v-else style="margin-top: 20rpx;" :class="['buttonBorder',!istrue?'dlbutton':'dlbutton_loading']" open-type="getUserInfo"
  25. @getuserinfo="wxLogin">
  26. <view :class="istrue?'rotate_loop':''">
  27. <text v-if="istrue" class="cuIcon cuIcon-loading1"></text>
  28. <view v-if="!istrue">
  29. <slot name="text">微信授权一键登录</slot>
  30. </view>
  31. </view>
  32. </button>
  33. <button style="margin-top: 20rpx;color:#0B73B9 ;" class="buttonBorder dlbutton" @click="toindex()">
  34. <slot name="text">游客登录</slot>
  35. </button>
  36. </view>
  37. <u-popup v-model="show" mode="center" :mask-close-able="false" border-radius="16">
  38. <view style="width: 500rpx;height: 400rpx;position: relative;" class="flex flex-direction align-center justify-center">
  39. <view class="text-xl text-bold" style="position: absolute;top:30rpx">
  40. 提示
  41. </view>
  42. <view class="text-gray margin-top-sm text-lg padding-lr-sm">
  43. 需要获取用户个人信息及资料方便后续注册
  44. </view>
  45. <button open-type="getUserInfo" style="width: 100%;font-size: 32rpx;position: absolute;bottom: 0;" @getuserinfo="wxLogin">确认授权</button>
  46. </view>
  47. </u-popup>
  48. <!-- 底部信息 -->
  49. <view class="footer">
  50. <view class="flex align-center">
  51. <image @click="isqueren" :src="imgitem.name" mode="" style="width: 30rpx;height: 30rpx;"></image>
  52. <text style="color: #0B73B9;">《超级宝妈宝》</text>
  53. <text style="color: #999999;">服务协议</text>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. var _this;
  61. import wInput from '../../components/watch-input.vue' //input
  62. import wButton from '../../components/watch-button.vue' //button
  63. var user = require('../../common/user.js');
  64. import {
  65. mapState,
  66. mapMutations,
  67. mapGetters,
  68. mapActions
  69. } from 'vuex';
  70. import store from '@/store'
  71. export default {
  72. computed: {
  73. ...mapGetters({
  74. hasLogin: 'verifyJwt'
  75. }),
  76. ...mapState(['user'])
  77. },
  78. data() {
  79. return {
  80. //logo图片 base64
  81. phoneData: '', // 用户/电话
  82. verCode: "", //验证码
  83. showAgree: true, //协议是否选择
  84. isRotate: false, //是否加载旋转
  85. istrue: false,
  86. num: 1,
  87. imgitem: {
  88. istrue: false,
  89. name: "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyi.png"
  90. },
  91. show: false,
  92. isphoneNum: false
  93. }
  94. },
  95. // onShow() {
  96. // uni.checkSession({
  97. // success() {
  98. // console.log("已登录")
  99. // return;
  100. // },
  101. // fail() {
  102. // uni.navigateTo({
  103. // url: "../doctor_related/doctor_info"
  104. // })
  105. // }
  106. // })
  107. // },
  108. components: {
  109. wInput,
  110. wButton,
  111. },
  112. mounted() {
  113. _this = this;
  114. },
  115. onLoad() {
  116. this.isphone()
  117. },
  118. methods: {
  119. isShowAgree() {
  120. //是否选择协议
  121. _this.showAgree = !_this.showAgree;
  122. },
  123. getVerCode: async function() {
  124. //获取验证码
  125. if (_this.phoneData.length != 11) {
  126. uni.showToast({
  127. icon: 'none',
  128. position: 'bottom',
  129. title: '手机号不正确'
  130. });
  131. return false;
  132. }
  133. let res = await this.$request.post("/api/v1/common/sendVerifyCode", {
  134. phone: this.phoneData,
  135. type: 1
  136. })
  137. console.log(res)
  138. if (res.status == 0) {
  139. this.$refs.runCode.$emit('runCode'); //触发倒计时(一般用于请求成功验证码后调用)
  140. }
  141. // _this.$refs.runCode.$emit('runCode', 0); //假装模拟下需要 终止倒计时
  142. },
  143. startReg: function() {
  144. //注册
  145. if (this.isRotate) {
  146. //判断是否加载中,避免重复点击请求
  147. return false;
  148. }
  149. if (!this.imgitem.istrue) {
  150. uni.showToast({
  151. icon: 'none',
  152. position: 'bottom',
  153. title: '请先同意协议'
  154. });
  155. return false;
  156. }
  157. if (this.phoneData.length != 11) {
  158. uni.showToast({
  159. icon: 'none',
  160. position: 'bottom',
  161. title: '手机号不正确'
  162. });
  163. return false;
  164. }
  165. if (this.verCode.length != 6) {
  166. uni.showToast({
  167. icon: 'none',
  168. position: 'bottom',
  169. title: '验证码不正确'
  170. });
  171. return false;
  172. }
  173. uni.login({
  174. success: (res) => {
  175. _this.isRotate = true
  176. this.$request.post("/api/v1/common/wxLogin", {
  177. wechat_code: res.code,
  178. phone: this.phoneData,
  179. verify_code: this.verCode
  180. }).then(res => {
  181. if (res.status == 0) {
  182. if (res.data.token) {
  183. store.commit('setJwt', res.data.token);
  184. store.commit('setUser', res.data);
  185. store.commit('login');
  186. uni.showToast({
  187. title: "登录成功",
  188. icon: "none"
  189. }, 1500)
  190. setTimeout(() => {
  191. uni.navigateBack({
  192. delta: 1
  193. })
  194. }, 1500)
  195. }
  196. }
  197. }).catch(err => {
  198. })
  199. }
  200. })
  201. },
  202. isphone: async function() {
  203. uni.login({
  204. success: (re) => {
  205. this.$request.post("/api/v1/common/getUserByCode", {
  206. wechat_code: re.code
  207. }).then(data => {
  208. console.log(data)
  209. if (data.data != null && data.data.phone != "") {
  210. this.isphoneNum = true
  211. }
  212. }).catch(err => {
  213. })
  214. }
  215. })
  216. },
  217. getphone: async function(e) {
  218. if (this.imgitem.istrue) {
  219. _this.istrue = true
  220. uni.login({
  221. success: (res) => {
  222. this.$request.post("/api/v1/common/getPhoneNumber", {
  223. wechat_code: res.code,
  224. iv: e.detail.iv,
  225. encryptData: e.detail.encryptedData
  226. }).then(data => {
  227. console.log(data)
  228. if (data.status == 0) {
  229. this.show = true
  230. } else {
  231. _this.istrue = false
  232. uni.showToast({
  233. title: "授权失败",
  234. icon: "none"
  235. })
  236. }
  237. }).catch(err => {
  238. })
  239. }
  240. })
  241. } else {
  242. uni.showToast({
  243. title: "请先同意协议",
  244. icon: "none"
  245. })
  246. }
  247. },
  248. wxLogin: async function(e) {
  249. if (e.detail.errMsg == "getUserInfo:fail auth deny") {
  250. uni.showToast({
  251. title: '微信登录失败',
  252. icon: "none"
  253. });
  254. return;
  255. }
  256. if (this.imgitem.istrue) {
  257. user.loginByWeixin(e.detail.userInfo)
  258. .then(res => {
  259. this.show = false
  260. if (res.status == 0) {
  261. uni.showToast({
  262. title: "登录成功",
  263. icon: "none",
  264. duration: 2000
  265. })
  266. }
  267. setTimeout(function() {
  268. _this.istrue = false
  269. uni.navigateBack({
  270. delta: 1
  271. })
  272. }, 2000)
  273. })
  274. .catch(res => {
  275. uni.showToast({
  276. title: '微信登录失败',
  277. icon: "none"
  278. });
  279. });
  280. }else{
  281. uni.showToast({
  282. title: "请先同意协议",
  283. icon: "none"
  284. })
  285. }
  286. },
  287. toindex() {
  288. uni.switchTab({
  289. url: "../index/index"
  290. })
  291. },
  292. isqueren() {
  293. this.num++
  294. if (this.num % 2 == 0) {
  295. this.imgitem.name = "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyixuan.png"
  296. this.imgitem.istrue = true
  297. } else {
  298. this.imgitem.name = "https://zhengda.oss-cn-chengdu.aliyuncs.com/baoma/static/img/xieyi.png"
  299. this.imgitem.istrue = false
  300. }
  301. }
  302. }
  303. }
  304. </script>
  305. <style>
  306. @import url("../../components/colorui/icon.css");
  307. @import url("./css/main.css");
  308. page {
  309. background-color: #fff;
  310. }
  311. .dlbutton {
  312. display: flex;
  313. justify-content: center;
  314. align-items: center;
  315. color: #84BB43;
  316. font-size: 30rpx;
  317. white-space: nowrap;
  318. overflow: hidden;
  319. width: 294rpx;
  320. height: 88rpx;
  321. background: linear-gradient(to right, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 255.6));
  322. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.4);
  323. border-radius: 2.5rem;
  324. margin-top: 0rpx;
  325. }
  326. .dlbutton_loading {
  327. display: flex;
  328. justify-content: center;
  329. align-items: center;
  330. color: #84BB43;
  331. font-size: 30rpx;
  332. width: 100rpx;
  333. height: 100rpx;
  334. background: linear-gradient(to right, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 255.6));
  335. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.4);
  336. border-radius: 2.5rem;
  337. margin-top: 0rpx;
  338. }
  339. .buttonBorder {
  340. border: none;
  341. border-radius: 2.5rem;
  342. -webkit-box-shadow: 0 0 60rpx 0 rgba(0, 0, 0, .2);
  343. box-shadow: 0 0 60rpx 0 rgba(0, 0, 0, .2);
  344. -webkit-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  345. -moz-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  346. -ms-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  347. -o-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  348. transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  349. }
  350. /* 旋转动画 */
  351. .rotate_loop {
  352. -webkit-transition-property: -webkit-transform;
  353. -webkit-transition-duration: 1s;
  354. -moz-transition-property: -moz-transform;
  355. -moz-transition-duration: 1s;
  356. -webkit-animation: rotate 1s linear infinite;
  357. -moz-animation: rotate 1s linear infinite;
  358. -o-animation: rotate 1s linear infinite;
  359. animation: rotate 1s linear infinite;
  360. }
  361. @-webkit-keyframes rotate {
  362. from {
  363. -webkit-transform: rotate(0deg)
  364. }
  365. to {
  366. -webkit-transform: rotate(360deg)
  367. }
  368. }
  369. @-moz-keyframes rotate {
  370. from {
  371. -moz-transform: rotate(0deg)
  372. }
  373. to {
  374. -moz-transform: rotate(359deg)
  375. }
  376. }
  377. @-o-keyframes rotate {
  378. from {
  379. -o-transform: rotate(0deg)
  380. }
  381. to {
  382. -o-transform: rotate(359deg)
  383. }
  384. }
  385. @keyframes rotate {
  386. from {
  387. transform: rotate(0deg)
  388. }
  389. to {
  390. transform: rotate(359deg)
  391. }
  392. }
  393. button::after {
  394. border: none;
  395. }
  396. </style>