login.vue 9.4 KB

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