login.vue 7.1 KB

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