login.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <view class="register">
  3. <view class="content">
  4. <!-- 头部logo -->
  5. <view class="header">
  6. <image src="../../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: "../../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. if (res.status == 0) {
  166. uni.showToast({
  167. title: "登录成功",
  168. icon: "none",
  169. duration: 2000
  170. })
  171. }
  172. setTimeout(function() {
  173. _this.istrue = false
  174. uni.navigateBack({
  175. delta: 1
  176. })
  177. }, 2000)
  178. })
  179. .catch(res => {
  180. uni.showToast({
  181. title: '微信登录失败',
  182. icon: "none"
  183. });
  184. });
  185. }else{
  186. uni.showToast({
  187. title:"请先同意协议",
  188. icon:"none"
  189. })
  190. }
  191. },
  192. toindex() {
  193. uni.switchTab({
  194. url: "../index/index"
  195. })
  196. },
  197. isqueren() {
  198. this.num++
  199. if (this.num % 2 == 0) {
  200. this.imgitem.name = "../../static/img/xieyixuan.png"
  201. this.imgitem.istrue = true
  202. } else {
  203. this.imgitem.name = "../../static/img/xieyi.png"
  204. this.imgitem.istrue = false
  205. }
  206. }
  207. }
  208. }
  209. </script>
  210. <style>
  211. @import url("../../components/colorui/icon.css");
  212. @import url("./css/main.css");
  213. page {
  214. background-color: #fff;
  215. }
  216. .dlbutton {
  217. display: flex;
  218. justify-content: center;
  219. align-items: center;
  220. color: #84BB43;
  221. font-size: 30rpx;
  222. white-space: nowrap;
  223. overflow: hidden;
  224. width: 294rpx;
  225. height: 88rpx;
  226. background: linear-gradient(to right, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 255.6));
  227. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.4);
  228. border-radius: 2.5rem;
  229. margin-top: 0rpx;
  230. }
  231. .dlbutton_loading {
  232. display: flex;
  233. justify-content: center;
  234. align-items: center;
  235. color: #84BB43;
  236. font-size: 30rpx;
  237. width: 100rpx;
  238. height: 100rpx;
  239. background: linear-gradient(to right, rgba(255, 255, 255, 0.7), rgba(255, 255, 255, 255.6));
  240. box-shadow: 0rpx 0rpx 13rpx 0rpx rgba(164, 217, 228, 0.4);
  241. border-radius: 2.5rem;
  242. margin-top: 0rpx;
  243. }
  244. .buttonBorder {
  245. border: none;
  246. border-radius: 2.5rem;
  247. -webkit-box-shadow: 0 0 60rpx 0 rgba(0, 0, 0, .2);
  248. box-shadow: 0 0 60rpx 0 rgba(0, 0, 0, .2);
  249. -webkit-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  250. -moz-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  251. -ms-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  252. -o-transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  253. transition: all 0.4s cubic-bezier(.57, .19, .51, .95);
  254. }
  255. /* 旋转动画 */
  256. .rotate_loop {
  257. -webkit-transition-property: -webkit-transform;
  258. -webkit-transition-duration: 1s;
  259. -moz-transition-property: -moz-transform;
  260. -moz-transition-duration: 1s;
  261. -webkit-animation: rotate 1s linear infinite;
  262. -moz-animation: rotate 1s linear infinite;
  263. -o-animation: rotate 1s linear infinite;
  264. animation: rotate 1s linear infinite;
  265. }
  266. @-webkit-keyframes rotate {
  267. from {
  268. -webkit-transform: rotate(0deg)
  269. }
  270. to {
  271. -webkit-transform: rotate(360deg)
  272. }
  273. }
  274. @-moz-keyframes rotate {
  275. from {
  276. -moz-transform: rotate(0deg)
  277. }
  278. to {
  279. -moz-transform: rotate(359deg)
  280. }
  281. }
  282. @-o-keyframes rotate {
  283. from {
  284. -o-transform: rotate(0deg)
  285. }
  286. to {
  287. -o-transform: rotate(359deg)
  288. }
  289. }
  290. @keyframes rotate {
  291. from {
  292. transform: rotate(0deg)
  293. }
  294. to {
  295. transform: rotate(359deg)
  296. }
  297. }
  298. button::after {
  299. border: none;
  300. }
  301. </style>