Login.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <template>
  2. <view>
  3. <view v-show="accountIsShow">
  4. <view class="title">账号密码登录</view>
  5. <view class="usernameAndPassword">
  6. <view class="usernameContent">
  7. <input type="text" v-model="username" placeholder="账号" @input="usernameInput"/>
  8. </view>
  9. <view class="passwordContent">
  10. <input type="text" v-model="password" :password="passwordShow" placeholder="请输入密码" @input="passwordInput"/>
  11. <sunui-password @change="showPass" />
  12. </view>
  13. </view>
  14. <view class="type" :style="{ 'margin-top': typeMarginTop }">
  15. <a @tap="changeType('phone')">手机验证码登录</a>
  16. <a style="float: right;color:#77A8E6;" @tap="goToIndex()">游客身份登录</a>
  17. </view>
  18. <button class="cu-btn bg-red lg" @tap="login" :disabled="usernameLoginDisabled" type="" :style="{ 'height': buttonHeight}">登录</button>
  19. <view class="bottomWord" :style="{ 'font-size': bottomWordFontSize,'margin-top':bottomWordMarginTop}">
  20. 点击登录,即代表已阅读并同意<a href="#">隐私政策</a>和<a href="#">用户协议</a>
  21. </view>
  22. </view>
  23. <view v-show="phoneIsShow">
  24. <view class="title">手机验证码登录</view>
  25. <view class="usernameAndPassword">
  26. <view class="phoneContent">
  27. <span>+86</span>
  28. <input type="text" v-model="phone" placeholder="请输入手机号码" @input="phoneInput" />
  29. </view>
  30. <view class="codeContent">
  31. <input type="text" v-model="code" placeholder="请输入验证码" @input="codeInput"/>
  32. <span :style="{ 'color': codeColor,'width':codeWidth }" @tap="getCode">获取验证码</span>
  33. </view>
  34. </view>
  35. <view class="type" :style="{ 'margin-top': typeMarginTop }">
  36. <a @tap="changeType('account')">账号登录</a>
  37. </view>
  38. <button class="cu-btn bg-red lg" :disabled="codeLoginDisabled" type="" :style="{ 'height': buttonHeight}">登录</button>
  39. <view class="bottomWord" :style="{ 'font-size': bottomWordFontSize,'margin-top':bottomWordMarginTop}">
  40. 点击登录,即代表已阅读并同意<a href="#">隐私政策</a>和<a href="#">用户协议</a>
  41. </view>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. export default {
  47. data: function() {
  48. return {
  49. passwordShow: true,
  50. accountIsShow:true,
  51. phoneIsShow:false,
  52. usernameLoginDisabled:true,
  53. codeLoginDisabled:true,
  54. username: '',
  55. password: '',
  56. phone:"",
  57. code:"",
  58. codeColor:"#808080",
  59. usernameFlag:false,
  60. passwordFlag:false,
  61. phoneFlag:false,
  62. codeFlag:false,
  63. getCodeFlag:false,
  64. lastUserName: '',
  65. lastPassWord: '',
  66. windowWidth:"",
  67. windowHeight:"",
  68. typeMarginTop:"",
  69. codeWidth:"",
  70. bottomWordFontSize:"",
  71. bottomWordMarginTop:"",
  72. buttonHeight:""
  73. };
  74. },
  75. created() {
  76. this.windowWidth = uni.getSystemInfoSync().windowWidth;
  77. this.windowHeight = uni.getSystemInfoSync().windowHeight;
  78. //console.log(this.windowWidth);
  79. if (this.windowWidth >= 768) {
  80. this.typeMarginTop="10%";
  81. this.codeWidth="200px";
  82. this.bottomWordFontSize="18px";
  83. this.bottomWordMarginTop="500px";
  84. this.buttonHeight="50px";
  85. } else {
  86. this.typeMarginTop="0";
  87. this.codeWidth="100px";
  88. this.bottomWordFontSize="13px";
  89. this.bottomWordMarginTop="270px";
  90. this.buttonHeight="40px";
  91. }
  92. //this.removeUsernamePassword();
  93. this.getUsernamePassword();
  94. },
  95. methods: {
  96. showPass(e) {
  97. this.passwordShow = e;
  98. },
  99. usernameInput(e){
  100. if(e.detail.value!=""){
  101. this.usernameFlag=true;
  102. if(this.passwordFlag){
  103. this.usernameLoginDisabled=false;
  104. }
  105. }else{
  106. this.usernameFlag=false;
  107. this.usernameLoginDisabled=true;
  108. }
  109. },
  110. passwordInput(e){
  111. if(e.detail.value!=""){
  112. this.passwordFlag=true;
  113. if(this.usernameFlag){
  114. this.usernameLoginDisabled=false;
  115. }
  116. }else{
  117. this.passwordFlag=false;
  118. this.usernameLoginDisabled=true;
  119. }
  120. },
  121. phoneInput(e){
  122. // console.log(e.detail.value)
  123. var phoneStr = e.detail.value;
  124. if(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phoneStr)){
  125. this.codeColor="black";
  126. this.getCodeFlag=true;
  127. this.phoneFlag=true;
  128. if(this.codeFlag){
  129. this.codeLoginDisabled=false;
  130. }
  131. }
  132. if(!(/^1(3|4|5|6|7|8|9)\d{9}$/.test(phoneStr))){
  133. this.codeColor="#808080";
  134. this.getCodeFlag=false;
  135. this.phoneFlag=false;
  136. this.codeLoginDisabled=true;
  137. }
  138. },
  139. codeInput(e){
  140. if(e.detail.value!=""){
  141. this.codeFlag=true;
  142. if(this.phoneFlag){
  143. this.codeLoginDisabled=false;
  144. }
  145. }else{
  146. this.codeFlag=false;
  147. this.codeLoginDisabled=true;
  148. }
  149. },
  150. getCode:function(){
  151. if(this.getCodeFlag){
  152. console.log("获取验证码")
  153. }else{
  154. console.log("不能获取验证码")
  155. }
  156. },
  157. changeType:function(type){
  158. if(type=="account"){
  159. this.accountIsShow=true;
  160. this.phoneIsShow=false;
  161. }
  162. if(type=="phone"){
  163. this.phoneIsShow=true;
  164. this.accountIsShow=false;
  165. }
  166. },
  167. goToIndex:function(){
  168. let _this = this;
  169. uni.request({
  170. url: 'http://49.4.78.143:8057/GyeeuserController/login?username='+'admin'+'&password='+'admin',
  171. data: {},
  172. method: 'GET',
  173. success: function(res) {
  174. console.log(res.data);
  175. if (res.data.code == 200) {
  176. _this.loginFalg = true;
  177. }
  178. },
  179. fail: () => {
  180. _this.tips = '网络错误,小程序端请检查合法域名';
  181. }
  182. });
  183. uni.switchTab({
  184. url: '/pages/index/Index'
  185. });
  186. console.log(this.username)
  187. },
  188. falseLogin: function() {
  189. if (this.username == 'admin' && this.password == 'admin') {
  190. this.setUsernamePassword();
  191. uni.switchTab({
  192. url: '/pages/index/Index'
  193. });
  194. }else{
  195. uni.showModal({
  196. content: '用户名密码输入错误,请核对'
  197. });
  198. this.username = '';
  199. this.password = '';
  200. }
  201. },
  202. setUsernamePassword: function() {
  203. uni.setStorageSync('gyeeusername', this.username);
  204. uni.setStorageSync('gyeepassword', this.password);
  205. },
  206. getUsernamePassword: function() {
  207. this.lastUserName = uni.getStorageSync('gyeeusername');
  208. this.lastPassWord = uni.getStorageSync('gyeepassword');
  209. if (this.lastUserName != '' && this.lastPassWord != '') {
  210. uni.switchTab({
  211. url: '/pages/index/Index'
  212. });
  213. }
  214. },
  215. removeUsernamePassword: function() {
  216. uni.removeStorageSync('gyeeusername');
  217. uni.removeStorageSync('gyeepassword');
  218. },
  219. login: function() {
  220. let _this = this;
  221. uni.request({
  222. url: 'http://localhost:8082/GyeeuserController/login?username=' + this.username + '&password=' + this.password,
  223. data: {},
  224. method: 'GET',
  225. success: function(res) {
  226. console.log(res.data);
  227. if (res.data.code == 200) {
  228. _this.setUsernamePassword();
  229. _this.loginFalg = true;
  230. _this.getUser();
  231. } else {
  232. uni.showModal({
  233. content: '用户名密码输入错误,请核对'
  234. });
  235. _this.username = '';
  236. _this.password = '';
  237. }
  238. },
  239. fail: () => {
  240. _this.tips = '网络错误,小程序端请检查合法域名';
  241. }
  242. });
  243. },
  244. getUser: function() {
  245. let _this = this;
  246. uni.request({
  247. url: 'http://49.4.78.143:8081/UserauthorityController/getUserSession',
  248. data: {},
  249. method: 'GET',
  250. success: function(res) {
  251. _this.lastUserName = res.data[0];
  252. _this.lastPassWord = res.data[1];
  253. _this.getWindPowerStation();
  254. },
  255. fail: () => {
  256. _this.tips = '网络错误,小程序端请检查合法域名';
  257. }
  258. });
  259. },
  260. getWindPowerStation: function() {
  261. let _this = this;
  262. uni.request({
  263. url: 'http://49.4.78.143:8081/UserauthorityController/selectuserauthority?userName=' + this.lastUserName + '&password=' + this.lastPassWord,
  264. data: {},
  265. method: 'GET',
  266. success: function(res) {
  267. _this.windPowerStations = res.data;
  268. //console.log(_this.windPowerStations);
  269. _this.windPowerStationId = _this.windPowerStations[0];
  270. if (_this.loginFalg) {
  271. if (_this.windPowerStationId == 'MHS_FDC') {
  272. _this.windpowerstationName = '麻黄山';
  273. }
  274. if (_this.windPowerStationId == 'NSS_FDC') {
  275. _this.windpowerstationName = '牛首山';
  276. }
  277. if (_this.windPowerStationId == 'XS_FDC') {
  278. _this.windpowerstationName = '香山';
  279. }
  280. if (_this.windPowerStationId == 'SBQ_FDC') {
  281. _this.windpowerstationName = '石板泉';
  282. }
  283. if (_this.windPowerStationId == 'QS_FDC') {
  284. _this.windpowerstationName = '青山';
  285. }
  286. if (_this.windPowerStationId == 'CL_FDC') {
  287. _this.windpowerstationName = '崇礼';
  288. }
  289. if (_this.windPowerStationId == 'KB_FDC') {
  290. _this.windpowerstationName = '康保';
  291. }
  292. if (_this.windPowerStationId == 'YMG_FDC') {
  293. _this.windpowerstationName = '雁门关';
  294. }
  295. if (_this.windPowerStationId == 'TY_FDC') {
  296. _this.windpowerstationName = '天源';
  297. }
  298. if (_this.windPowerStationId == 'AL_FDC') {
  299. _this.windpowerstationName = '熬伦';
  300. }
  301. if (_this.windPowerStationId == 'DBS_FDC') {
  302. _this.windpowerstationName = '调兵山';
  303. }
  304. if (_this.windPowerStationId == 'BZ_FDC') {
  305. _this.windpowerstationName = '北镇';
  306. }
  307. if (_this.windPowerStationId == 'XC_FDC') {
  308. _this.windpowerstationName = '兴城';
  309. }
  310. if (_this.windPowerStationId == 'FS_FDC') {
  311. _this.windpowerstationName = '芳山';
  312. }
  313. if (_this.windPowerStationId == 'LH_FDC') {
  314. _this.windpowerstationName = '凌海';
  315. }
  316. if (_this.windPowerStationId == 'XBQ_FDC') {
  317. _this.windpowerstationName = '西八千';
  318. }
  319. if (_this.windPowerStationId == 'TZS_FDC') {
  320. _this.windpowerstationName = '台子山';
  321. }
  322. if (_this.windPowerStationId == 'YM_FDC') {
  323. _this.windpowerstationName = '永茂';
  324. }
  325. if (_this.windPowerStationId == 'WF_FDC') {
  326. _this.windpowerstationName = '万发';
  327. }
  328. } else {
  329. _this.windpowerstationName = '游客身份浏览';
  330. }
  331. _this.pushWindPowerStationNameToSessionStorage(_this.windpowerstationName);
  332. },
  333. fail: () => {
  334. _this.tips = '网络错误,小程序端请检查合法域名';
  335. }
  336. });
  337. },
  338. pushWindPowerStationNameToSessionStorage(windpowerstationName) {
  339. uni.setStorageSync('windpowerstationName', windpowerstationName);
  340. uni.setStorageSync('windpowerstationNames', JSON.stringify(this.windPowerStations));
  341. uni.setStorageSync('windPowerStationId', this.windPowerStationId);
  342. uni.switchTab({
  343. url: '/pages/index/Index'
  344. });
  345. //sessionStorage.setItem('windpowerstationName', windpowerstationName);
  346. //alert("v"+ sessionStorage.getItem("windpowerstationName"));
  347. //this.common.goback('/pages/index/Index');
  348. },
  349. noLogin: function() {
  350. let _this = this;
  351. uni.request({
  352. url: 'http://49.4.78.143:8081/admin/appLogin?username=abc&password=123',
  353. data: {},
  354. method: 'GET',
  355. success: function(res) {
  356. console.log(res.data);
  357. if (res.data.code == 200) {
  358. _this.loginFalg = false;
  359. _this.getUser();
  360. }
  361. },
  362. fail: () => {
  363. _this.tips = '网络错误,小程序端请检查合法域名';
  364. }
  365. });
  366. }
  367. }
  368. };
  369. </script>
  370. <style>
  371. page {
  372. height: 100%;
  373. /* background: -webkit-gradient(linear, 0% 100%, 0% 0%, from(#2f698e), color-stop(0.15, #5c757c), to(#004c90)); */
  374. }
  375. .title {
  376. width: 90%;
  377. height: 100px;
  378. font-size: 25px;
  379. font-weight: bold;
  380. padding-top: 50px;
  381. /* margin-top: 80px; */
  382. margin-left: 10%;
  383. }
  384. .usernameAndPassword {
  385. width: 100%;
  386. height: 100px;
  387. margin-top: 50px;
  388. }
  389. .usernameContent {
  390. width: 80%;
  391. margin-left: 10%;
  392. border-bottom: 2upx solid #D3D3D3;
  393. }
  394. .passwordContent {
  395. width: 80%;
  396. display: flex;
  397. align-items: center;
  398. justify-content: space-between;
  399. border-bottom: 2upx solid #D3D3D3;
  400. margin-top: 20px;
  401. margin-left: 10%;
  402. }
  403. input {
  404. width: 100%;
  405. height: 30px;
  406. }
  407. .type{
  408. width: 80%;
  409. height: 20px;
  410. line-height: 20px;
  411. margin-left: 10%;
  412. }
  413. .cu-btn {
  414. width: 80%;
  415. height: 40px;
  416. margin-left: 10%;
  417. margin-top: 25px;
  418. }
  419. .phoneContent{
  420. width: 80%;
  421. margin-left: 10%;
  422. border-bottom: 2upx solid #D3D3D3;
  423. display: flex;
  424. }
  425. .phoneContent span{
  426. line-height: 30px;
  427. margin-right: 5px;
  428. }
  429. .codeContent{
  430. width: 80%;
  431. margin-left: 10%;
  432. border-bottom: 2upx solid #D3D3D3;
  433. display: flex;
  434. margin-top: 20px;
  435. }
  436. .codeContent span{
  437. width: 100px;
  438. }
  439. .bottomWord{
  440. width: 80%;
  441. margin-left: 10%;
  442. color: #808080;
  443. font-size: 13px;
  444. margin-top: 270px;
  445. text-align: center;
  446. }
  447. a{
  448. text-decoration: none;
  449. }
  450. .bottomWord a:link {
  451. color: #5C97E4;
  452. }
  453. .bottomWord a:hover {
  454. color: #5C97E4;
  455. }
  456. .bottomWord a:visited {
  457. color: #5C97E4;
  458. }
  459. .bottomWord a:active {
  460. color: #5C97E4;
  461. }
  462. /* .container {
  463. border-radius: 20px;
  464. width: 90%;
  465. height: 700upx;
  466. margin: 0px auto;
  467. position: absolute;
  468. top: 20%;
  469. left: 5%;
  470. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#024f93), color-stop(1.5, #cccccc), to(#437193));
  471. background: rgba(0, 0, 0, 0.1);
  472. }
  473. .title {
  474. width: 100%;
  475. height: 50px;
  476. color: white;
  477. line-height: 50px;
  478. text-align: center;
  479. margin-top: 5%;
  480. }
  481. .usernameContainer {
  482. width: 100%;
  483. height: 40px;
  484. line-height: 40px;
  485. margin-top: 10%;
  486. }
  487. .usernameContainer span {
  488. float: left;
  489. font-size: 18px;
  490. color: white;
  491. margin-left: 10px;
  492. }
  493. .username {
  494. width: 70%;
  495. height: 40px;
  496. border: 1px solid white;
  497. float: left;
  498. border-radius: 5px;
  499. }
  500. .passwordContainer {
  501. width: 100%;
  502. height: 40px;
  503. line-height: 40px;
  504. margin-top: 10%;
  505. }
  506. .passwordContainer span {
  507. float: left;
  508. font-size: 18px;
  509. color: white;
  510. margin-left: 10px;
  511. }
  512. .password {
  513. width: 70%;
  514. height: 40px;
  515. border: 1px solid white;
  516. float: left;
  517. border-radius: 5px;
  518. }
  519. .noLogin {
  520. width: calc(70% + 84px);
  521. height: 40px;
  522. text-align: right;
  523. color: white;
  524. //margin-left:15% ;
  525. //margin-right: 10px;
  526. line-height: 40px;
  527. }
  528. .noLogin a:link {
  529. color: white;
  530. }
  531. .noLogin a:hover {
  532. color: white;
  533. }
  534. .noLogin a:visited {
  535. color: white;
  536. }
  537. .noLogin a:active {
  538. color: white;
  539. }
  540. .cu-btn {
  541. width: 80%;
  542. height: 50px;
  543. margin-left: 10%;
  544. //margin-top: 10%;
  545. } */
  546. </style>