login.vue 6.9 KB

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