login.vue 6.8 KB

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