Login.vue 14 KB

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