Login.vue 14 KB

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