login.vue 7.2 KB

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