Login.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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="falseLogin" :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://49.4.78.143:8081/admin/appLogin?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.loginFalg = true;
  229. _this.getUser();
  230. } else {
  231. uni.showModal({
  232. content: '用户名密码输入错误,请核对'
  233. });
  234. _this.username = '';
  235. _this.password = '';
  236. }
  237. },
  238. fail: () => {
  239. _this.tips = '网络错误,小程序端请检查合法域名';
  240. }
  241. });
  242. },
  243. getUser: function() {
  244. let _this = this;
  245. uni.request({
  246. url: 'http://49.4.78.143:8081/UserauthorityController/getUserSession',
  247. data: {},
  248. method: 'GET',
  249. success: function(res) {
  250. _this.lastUserName = res.data[0];
  251. _this.lastPassWord = res.data[1];
  252. _this.getWindPowerStation();
  253. },
  254. fail: () => {
  255. _this.tips = '网络错误,小程序端请检查合法域名';
  256. }
  257. });
  258. },
  259. getWindPowerStation: function() {
  260. let _this = this;
  261. uni.request({
  262. url: 'http://49.4.78.143:8081/UserauthorityController/selectuserauthority?userName=' + this.lastUserName + '&password=' + this.lastPassWord,
  263. data: {},
  264. method: 'GET',
  265. success: function(res) {
  266. _this.windPowerStations = res.data;
  267. //console.log(_this.windPowerStations);
  268. _this.windPowerStationId = _this.windPowerStations[0];
  269. if (_this.loginFalg) {
  270. if (_this.windPowerStationId == 'MHS_FDC') {
  271. _this.windpowerstationName = '麻黄山';
  272. }
  273. if (_this.windPowerStationId == 'NSS_FDC') {
  274. _this.windpowerstationName = '牛首山';
  275. }
  276. if (_this.windPowerStationId == 'XS_FDC') {
  277. _this.windpowerstationName = '香山';
  278. }
  279. if (_this.windPowerStationId == 'SBQ_FDC') {
  280. _this.windpowerstationName = '石板泉';
  281. }
  282. if (_this.windPowerStationId == 'QS_FDC') {
  283. _this.windpowerstationName = '青山';
  284. }
  285. if (_this.windPowerStationId == 'CL_FDC') {
  286. _this.windpowerstationName = '崇礼';
  287. }
  288. if (_this.windPowerStationId == 'KB_FDC') {
  289. _this.windpowerstationName = '康保';
  290. }
  291. if (_this.windPowerStationId == 'YMG_FDC') {
  292. _this.windpowerstationName = '雁门关';
  293. }
  294. if (_this.windPowerStationId == 'TY_FDC') {
  295. _this.windpowerstationName = '天源';
  296. }
  297. if (_this.windPowerStationId == 'AL_FDC') {
  298. _this.windpowerstationName = '熬伦';
  299. }
  300. if (_this.windPowerStationId == 'DBS_FDC') {
  301. _this.windpowerstationName = '调兵山';
  302. }
  303. if (_this.windPowerStationId == 'BZ_FDC') {
  304. _this.windpowerstationName = '北镇';
  305. }
  306. if (_this.windPowerStationId == 'XC_FDC') {
  307. _this.windpowerstationName = '兴城';
  308. }
  309. if (_this.windPowerStationId == 'FS_FDC') {
  310. _this.windpowerstationName = '芳山';
  311. }
  312. if (_this.windPowerStationId == 'LH_FDC') {
  313. _this.windpowerstationName = '凌海';
  314. }
  315. if (_this.windPowerStationId == 'XBQ_FDC') {
  316. _this.windpowerstationName = '西八千';
  317. }
  318. if (_this.windPowerStationId == 'TZS_FDC') {
  319. _this.windpowerstationName = '台子山';
  320. }
  321. if (_this.windPowerStationId == 'YM_FDC') {
  322. _this.windpowerstationName = '永茂';
  323. }
  324. if (_this.windPowerStationId == 'WF_FDC') {
  325. _this.windpowerstationName = '万发';
  326. }
  327. } else {
  328. _this.windpowerstationName = '游客身份浏览';
  329. }
  330. _this.pushWindPowerStationNameToSessionStorage(_this.windpowerstationName);
  331. },
  332. fail: () => {
  333. _this.tips = '网络错误,小程序端请检查合法域名';
  334. }
  335. });
  336. },
  337. pushWindPowerStationNameToSessionStorage(windpowerstationName) {
  338. uni.setStorageSync('windpowerstationName', windpowerstationName);
  339. uni.setStorageSync('windpowerstationNames', JSON.stringify(this.windPowerStations));
  340. uni.setStorageSync('windPowerStationId', this.windPowerStationId);
  341. uni.switchTab({
  342. url: '/pages/index/Index'
  343. });
  344. //sessionStorage.setItem('windpowerstationName', windpowerstationName);
  345. //alert("v"+ sessionStorage.getItem("windpowerstationName"));
  346. //this.common.goback('/pages/index/Index');
  347. },
  348. noLogin: function() {
  349. let _this = this;
  350. uni.request({
  351. url: 'http://49.4.78.143:8081/admin/appLogin?username=abc&password=123',
  352. data: {},
  353. method: 'GET',
  354. success: function(res) {
  355. console.log(res.data);
  356. if (res.data.code == 200) {
  357. _this.loginFalg = false;
  358. _this.getUser();
  359. }
  360. },
  361. fail: () => {
  362. _this.tips = '网络错误,小程序端请检查合法域名';
  363. }
  364. });
  365. }
  366. }
  367. };
  368. </script>
  369. <style>
  370. page {
  371. height: 100%;
  372. /* background: -webkit-gradient(linear, 0% 100%, 0% 0%, from(#2f698e), color-stop(0.15, #5c757c), to(#004c90)); */
  373. }
  374. .title {
  375. width: 90%;
  376. height: 100px;
  377. font-size: 25px;
  378. font-weight: bold;
  379. padding-top: 50px;
  380. /* margin-top: 80px; */
  381. margin-left: 10%;
  382. }
  383. .usernameAndPassword {
  384. width: 100%;
  385. height: 100px;
  386. margin-top: 50px;
  387. }
  388. .usernameContent {
  389. width: 80%;
  390. margin-left: 10%;
  391. border-bottom: 2upx solid #D3D3D3;
  392. }
  393. .passwordContent {
  394. width: 80%;
  395. display: flex;
  396. align-items: center;
  397. justify-content: space-between;
  398. border-bottom: 2upx solid #D3D3D3;
  399. margin-top: 20px;
  400. margin-left: 10%;
  401. }
  402. input {
  403. width: 100%;
  404. height: 30px;
  405. }
  406. .type{
  407. width: 80%;
  408. height: 20px;
  409. line-height: 20px;
  410. margin-left: 10%;
  411. }
  412. .cu-btn {
  413. width: 80%;
  414. height: 40px;
  415. margin-left: 10%;
  416. margin-top: 25px;
  417. }
  418. .phoneContent{
  419. width: 80%;
  420. margin-left: 10%;
  421. border-bottom: 2upx solid #D3D3D3;
  422. display: flex;
  423. }
  424. .phoneContent span{
  425. line-height: 30px;
  426. margin-right: 5px;
  427. }
  428. .codeContent{
  429. width: 80%;
  430. margin-left: 10%;
  431. border-bottom: 2upx solid #D3D3D3;
  432. display: flex;
  433. margin-top: 20px;
  434. }
  435. .codeContent span{
  436. width: 100px;
  437. }
  438. .bottomWord{
  439. width: 80%;
  440. margin-left: 10%;
  441. color: #808080;
  442. font-size: 13px;
  443. margin-top: 270px;
  444. text-align: center;
  445. }
  446. a{
  447. text-decoration: none;
  448. }
  449. .bottomWord a:link {
  450. color: #5C97E4;
  451. }
  452. .bottomWord a:hover {
  453. color: #5C97E4;
  454. }
  455. .bottomWord a:visited {
  456. color: #5C97E4;
  457. }
  458. .bottomWord a:active {
  459. color: #5C97E4;
  460. }
  461. /* .container {
  462. border-radius: 20px;
  463. width: 90%;
  464. height: 700upx;
  465. margin: 0px auto;
  466. position: absolute;
  467. top: 20%;
  468. left: 5%;
  469. background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#024f93), color-stop(1.5, #cccccc), to(#437193));
  470. background: rgba(0, 0, 0, 0.1);
  471. }
  472. .title {
  473. width: 100%;
  474. height: 50px;
  475. color: white;
  476. line-height: 50px;
  477. text-align: center;
  478. margin-top: 5%;
  479. }
  480. .usernameContainer {
  481. width: 100%;
  482. height: 40px;
  483. line-height: 40px;
  484. margin-top: 10%;
  485. }
  486. .usernameContainer span {
  487. float: left;
  488. font-size: 18px;
  489. color: white;
  490. margin-left: 10px;
  491. }
  492. .username {
  493. width: 70%;
  494. height: 40px;
  495. border: 1px solid white;
  496. float: left;
  497. border-radius: 5px;
  498. }
  499. .passwordContainer {
  500. width: 100%;
  501. height: 40px;
  502. line-height: 40px;
  503. margin-top: 10%;
  504. }
  505. .passwordContainer span {
  506. float: left;
  507. font-size: 18px;
  508. color: white;
  509. margin-left: 10px;
  510. }
  511. .password {
  512. width: 70%;
  513. height: 40px;
  514. border: 1px solid white;
  515. float: left;
  516. border-radius: 5px;
  517. }
  518. .noLogin {
  519. width: calc(70% + 84px);
  520. height: 40px;
  521. text-align: right;
  522. color: white;
  523. //margin-left:15% ;
  524. //margin-right: 10px;
  525. line-height: 40px;
  526. }
  527. .noLogin a:link {
  528. color: white;
  529. }
  530. .noLogin a:hover {
  531. color: white;
  532. }
  533. .noLogin a:visited {
  534. color: white;
  535. }
  536. .noLogin a:active {
  537. color: white;
  538. }
  539. .cu-btn {
  540. width: 80%;
  541. height: 50px;
  542. margin-left: 10%;
  543. //margin-top: 10%;
  544. } */
  545. </style>