login.vue 7.6 KB

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