login.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  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/getLoginAuthorize',
  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. alert('res.data.flag');
  191. alert(res.data.flag);
  192. alert('res.data.msg')
  193. alert(res.data.msg)
  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. alert('初始化')
  207. alert(res.data.flag)
  208. alert(res.data.msg)
  209. if(res.data.flag == true){
  210. uni.switchTab({
  211. url: '/pages/index/index'
  212. });
  213. }
  214. },
  215. }
  216. }
  217. </script>
  218. <style>
  219. .section {
  220. height: 400rpx;
  221. background-image: url(/static/login-bg.png);
  222. background-size: cover;
  223. background-repeat: no-repeat;
  224. }
  225. .content {
  226. height: 434rpx;
  227. text-align: center;
  228. position: relative;
  229. }
  230. .login-box {
  231. height: 600rpx;
  232. position: relative;
  233. top: -150rpx;
  234. background: #fff;
  235. border-radius: 30rpx;
  236. padding: 100rpx 20rpx;
  237. }
  238. .shadow {
  239. box-shadow: 1px 1px 4px rgb(26 26 26 / 10%);
  240. }
  241. .title {
  242. position: absolute;
  243. color: #fff;
  244. font-size: 60rpx;
  245. bottom: 180rpx;
  246. display: block;
  247. width: 100%;
  248. }
  249. input,
  250. button {
  251. width: 100%;
  252. height: 100rpx;
  253. line-height: 100rpx;
  254. opacity: 1;
  255. border: 1px solid #dbdbdb;
  256. border-radius: 100rpx;
  257. background: #fff;
  258. coloe: #333;
  259. margin: 40rpx 0;
  260. font-size: 34rpx;
  261. }
  262. input {
  263. text-indent: 100rpx;
  264. }
  265. .submit {
  266. background: #4074E7;
  267. color: #fff
  268. }
  269. .phone-box,
  270. .password-box {
  271. position: relative;
  272. }
  273. .phone-box text,
  274. .password-box text {
  275. font-size: 30rpx;
  276. color: #999999
  277. }
  278. .left-icon {
  279. position: absolute;
  280. left: 48rpx;
  281. top: 50%;
  282. margin-top: -20rpx;
  283. line-height: 100%
  284. }
  285. .right-icon {
  286. position: absolute;
  287. right: 48rpx;
  288. top: 50%;
  289. margin-top: -20rpx;
  290. line-height: 100%
  291. }
  292. .right-icon.verify {
  293. margin-top: -10rpx;
  294. color: #4074E7
  295. }
  296. .iconfont {
  297. color: #999
  298. }
  299. /* 底部 */
  300. .box {
  301. display: none;
  302. position: fixed;
  303. bottom: 0;
  304. width: 100%;
  305. border-top: 1px solid pink
  306. }
  307. .cuIcon-cu-image .iconfont {
  308. width: 38rpx;
  309. height: 38rpx;
  310. display: inline-block;
  311. margin-bottom: 10rpx;
  312. }
  313. .text-gray {
  314. font-size: 26rpx;
  315. }
  316. </style>