login.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <view class="section">
  3. <view class="text-area content">
  4. <text class="title">智慧消防</text>
  5. </view>
  6. <form class="padding-lg flex flex-direction">
  7. <view class="login-box shadow ">
  8. <view class="phone-box">
  9. <input type="text" placeholder="请输入手机号码" onfocus="this.placeholder=''" v-model="phone">
  10. <span class="icon iconfont left-icon">&#xe64f;</span>
  11. <span class="icon iconfont right-icon">&#xe610;</span>
  12. </view>
  13. <view class="password-box">
  14. <input type="text" placeholder="请输入验证码" v-model="verify">
  15. <text class="icon iconfont left-icon">&#xe86a;</text>
  16. <view @click="getVerifyCode">
  17. <text class="right-icon verify">{{!codeTime?'获取验证码':codeTime+'s'}}</text>
  18. </view>
  19. </view>
  20. <view class="btn-area">
  21. <button class="submit" @click="submitRes">提 交 </button>
  22. </view>
  23. </view>
  24. </form>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. codeTime: 0,
  32. phone: '',
  33. verify: '',
  34. VerificationCodeOne: ''
  35. }
  36. },
  37. onLoad() {
  38. this.init()
  39. uni.setNavigationBarColor({
  40. frontColor: "#ffffff", //文字颜色
  41. backgroundColor: "#4866DF", //底部背景色
  42. })
  43. },
  44. methods: {
  45. // 初始化 start
  46. getUrlCode() {
  47. var url = location.search
  48. this.winUrl = url
  49. var theRequest = new Object()
  50. if (url.indexOf("?") != -1) {
  51. var str = url.substr(1)
  52. var strs = str.split("&")
  53. for (var i = 0; i < strs.length; i++) {
  54. theRequest[strs[i].split("=")[0]] = (strs[i].split("=")[1])
  55. }
  56. }
  57. return theRequest
  58. },
  59. async init() {
  60. let ua = navigator.userAgent.toLowerCase();
  61. if (ua.match(/MicroMessenger/i) == "micromessenger") {
  62. var curl2 = window.location.href;
  63. //是
  64. var appId = "wx4eab2e3b5531d58b";
  65. var params = {};
  66. var CODE = this.getUrlCode();
  67. var code = CODE['code'];
  68. if (code) {
  69. params.code = code;
  70. const res = await this.$myRequest({
  71. url: 'Login/getLoginAuthorize',
  72. data: params
  73. })
  74. // if (res.data.flag == true) {
  75. // uni.switchTab({
  76. // url: '/pages/index/index'
  77. // });
  78. // }
  79. code = '';
  80. return "ok";
  81. }
  82. var cs = {};
  83. var curl = window.location.href;
  84. cs.curl = curl;
  85. const res1 = await this.$myRequest({
  86. url: 'Login/getLoginAuthorize',
  87. data: cs
  88. })
  89. var turl = res1.data.turl;
  90. window.location.href =
  91. 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx4eab2e3b5531d58b&redirect_uri=' + turl +
  92. '&response_type=code&scope=snsapi_base&state=abc123#wechat_redirect';
  93. } else {
  94. const res = await this.$myRequest({
  95. url: 'Login/getLoginAuthorize',
  96. data: params
  97. })
  98. }
  99. },
  100. // 初始化 end
  101. //点击获取验证码
  102. getVerifyCode() {
  103. if (!this.phone) {
  104. uni.showToast({
  105. title: "请输入手机号码...",
  106. icon: "none"
  107. });
  108. return
  109. }
  110. if (!/^1[345678]\d{9}$/.test(this.phone)) {
  111. uni.showToast({
  112. title: "请输入正确的手机号码...",
  113. icon: "none"
  114. });
  115. return
  116. }
  117. this.getVerifyData({
  118. "phone": this.phone
  119. })
  120. //
  121. if (this.codeTime > 0) {
  122. uni.showToast({
  123. title: '不能重复获取',
  124. icon: "none"
  125. });
  126. return;
  127. } else {
  128. this.codeTime = 60
  129. let timer = setInterval(() => {
  130. this.codeTime--;
  131. if (this.codeTime < 1) {
  132. clearInterval(timer);
  133. this.codeTime = 0
  134. }
  135. }, 1000)
  136. }
  137. },
  138. //点击提交按钮
  139. submitRes() {
  140. if (!this.phone) {
  141. uni.showToast({
  142. title: "请输入手机号码...",
  143. icon: "none"
  144. });
  145. return
  146. }
  147. if (!/^1[345678]\d{9}$/.test(this.phone)) {
  148. uni.showToast({
  149. title: "请输入正确的手机号码...",
  150. icon: "none"
  151. });
  152. return
  153. }
  154. if (!this.verify) {
  155. uni.showToast({
  156. title: "请输入验证码...",
  157. icon: "none"
  158. });
  159. return
  160. }
  161. this.getData({
  162. "phone": this.phone,
  163. "VerificationCode": this.verify,
  164. "VerificationCodeOne": this.VerificationCodeOne
  165. })
  166. },
  167. async getVerifyData(params = {}) {
  168. const res = await this.$myRequest({
  169. url: 'Login/getVerificationCode',
  170. data: params
  171. })
  172. this.VerificationCodeOne = eval('(' + res.data + ')').data[0].VerificationCode
  173. },
  174. async getData(params = {}) {
  175. const res = await this.$myRequest({
  176. url: 'Login/setSignUp',
  177. data: params
  178. })
  179. if (res.data.flag == true) {
  180. uni.switchTab({
  181. url: '/pages/index/index'
  182. });
  183. } else {
  184. }
  185. },
  186. }
  187. }
  188. </script>
  189. <style>
  190. .section {
  191. height: 400rpx;
  192. background-image: url(/static/login-bg.png);
  193. background-size: cover;
  194. background-repeat: no-repeat;
  195. }
  196. .content {
  197. height: 434rpx;
  198. text-align: center;
  199. position: relative;
  200. }
  201. .login-box {
  202. height: 600rpx;
  203. position: relative;
  204. top: -150rpx;
  205. background: #fff;
  206. border-radius: 30rpx;
  207. padding: 100rpx 20rpx;
  208. }
  209. .shadow {
  210. box-shadow: 0px 2px 4px rgb(26 26 26 / 10%);
  211. }
  212. .title {
  213. position: absolute;
  214. color: #fff;
  215. font-size: 60rpx;
  216. bottom: 180rpx;
  217. display: block;
  218. width: 100%;
  219. }
  220. input,
  221. button {
  222. width: 100%;
  223. height: 100rpx;
  224. line-height: 100rpx;
  225. opacity: 1;
  226. border: 1px solid #dbdbdb;
  227. border-radius: 100rpx;
  228. background: #fff;
  229. coloe: #333;
  230. margin: 40rpx 0;
  231. font-size: 34rpx;
  232. }
  233. input {
  234. text-indent: 100rpx;
  235. }
  236. .submit {
  237. background: #4074E7;
  238. color: #fff
  239. }
  240. .phone-box,
  241. .password-box {
  242. position: relative;
  243. }
  244. .password-box .verify {
  245. font-size: 30rpx;
  246. color: #999999
  247. }
  248. .left-icon {
  249. position: absolute;
  250. left: 48rpx;
  251. top: 50%;
  252. margin-top: -20rpx;
  253. line-height: 100%;
  254. font-size: 40rpx;
  255. color: #7A7A7A
  256. }
  257. .right-icon {
  258. position: absolute;
  259. right: 48rpx;
  260. top: 50%;
  261. margin-top: -20rpx;
  262. line-height: 100%;
  263. font-size: 40rpx;
  264. }
  265. .right-icon.verify {
  266. margin-top: -10rpx;
  267. color: #4074E7
  268. }
  269. .iconfont {
  270. color: #999
  271. }
  272. </style>