login.vue 7.1 KB

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