login.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. <template>
  2. <view class="login-container">
  3. <!-- 顶部渐变背景区域 -->
  4. <view class="header-bg"></view>
  5. <!-- Logo 区域(长按显示设置按钮) -->
  6. <view class="logo-section" @longpress="logoTime">
  7. <view class="logo-circle">
  8. <image
  9. src="./assets/logo.png"
  10. class="logo-img"
  11. mode="aspectFit"
  12. ></image>
  13. </view>
  14. <text class="app-title">{{
  15. $isneutral ? '智慧农业大数据平台' : '云飞智控'
  16. }}</text>
  17. </view>
  18. <!-- 设置按钮(长按 Logo 显示) -->
  19. <view class="set-btn" @click="set" v-if="setTF">
  20. <u-icon name="setting-fill" size="44" color="#24b35d"></u-icon>
  21. </view>
  22. <!-- 登录表单卡片 -->
  23. <view class="form-card">
  24. <form @submit="formSubmit">
  25. <!-- 账号输入 -->
  26. <view class="form-item">
  27. <u-icon name="account" size="36" color="#999"></u-icon>
  28. <u-input
  29. v-model="formdata.username"
  30. class="form-input"
  31. placeholder="请输入账号/手机号"
  32. placeholderStyle="color:#BBBBBB;"
  33. color="#333"
  34. :border="false"
  35. @blur="blur"
  36. />
  37. </view>
  38. <!-- 密码输入 -->
  39. <view class="form-item">
  40. <u-icon name="lock" size="36" color="#999"></u-icon>
  41. <u-input
  42. v-model="formdata.passwold"
  43. type="password"
  44. :password-icon="true"
  45. :clearable="false"
  46. placeholder="请输入密码"
  47. placeholderStyle="color:#BBBBBB;"
  48. suffixIconStyle="color:#999;"
  49. color="#333"
  50. :border="false"
  51. class="form-input"
  52. @confirm="formSubmit"
  53. @input="passwoldddata"
  54. />
  55. </view>
  56. <!-- 记住密码 -->
  57. <view class="form-extra">
  58. <u-checkbox-group>
  59. <u-checkbox
  60. v-model="checked"
  61. shape="square"
  62. size="28"
  63. active-color="#24b35d"
  64. :label-disabled="false"
  65. @change="rempass"
  66. >记住密码</u-checkbox
  67. >
  68. </u-checkbox-group>
  69. </view>
  70. <!-- 登录按钮 -->
  71. <view class="login-btn-wrap">
  72. <button form-type="submit" class="login-btn" @click="denglu">
  73. 登 录
  74. </button>
  75. </view>
  76. <!-- 用户隐私协议 -->
  77. <view class="agreement">
  78. <u-checkbox-group>
  79. <u-checkbox
  80. v-model="agree"
  81. shape="circle"
  82. size="26"
  83. active-color="#24b35d"
  84. :label-disabled="false"
  85. >
  86. 我已阅读并同意
  87. </u-checkbox>
  88. </u-checkbox-group>
  89. <text class="agree-link" @click="goAgreement">《用户隐私协议》</text>
  90. </view>
  91. </form>
  92. </view>
  93. <!-- 底部版本号 -->
  94. <view class="version-footer">
  95. <text class="version-text">V{{ appVersion || '1.0.0' }}</text>
  96. </view>
  97. <!-- 设置服务器地址弹窗 -->
  98. <view class="setbg" v-if="setbgtf">
  99. <view class="mengban" @click.stop="setbgtf = !setbgtf"></view>
  100. <view class="set_http">
  101. <view class="set_http_top">
  102. <u-icon name="close" size="40" @click="setbgtf = !setbgtf"></u-icon>
  103. <text class="set_title">设置服务器地址</text>
  104. <u-icon name="checkbox-mark" size="40" @click="sethttp"></u-icon>
  105. </view>
  106. <view class="set_http_bot">
  107. <text class="set_label">服务器访问地址</text>
  108. <view class="set_http_bot_input">
  109. <input
  110. type="text"
  111. v-model="value"
  112. placeholder="请在此处输入服务器地址(http://...)"
  113. />
  114. <u-icon
  115. :name="arrowtf ? 'arrow-up' : 'arrow-down'"
  116. @click="arrow"
  117. ></u-icon>
  118. </view>
  119. <scroll-view scroll-y="true" class="scroll-Y" v-if="arrowtf">
  120. <view
  121. :id="'demo' + index"
  122. class="scroll-view-item"
  123. v-for="(item, index) in httparr"
  124. :key="index"
  125. @click="value = item"
  126. >{{ item }}</view
  127. >
  128. </scroll-view>
  129. </view>
  130. </view>
  131. </view>
  132. <!-- 升级弹窗 -->
  133. <u-modal
  134. title="升级中请勿随意操作"
  135. :show-confirm-button="false"
  136. v-model="showA"
  137. :content="contentA"
  138. >
  139. <view class="upgradeBox">
  140. <u-line-progress
  141. v-show="isShow"
  142. active-color="#24b35d"
  143. :striped="true"
  144. :percent="percentNum"
  145. :striped-active="true"
  146. ></u-line-progress>
  147. </view>
  148. </u-modal>
  149. </view>
  150. </template>
  151. <script>
  152. export default {
  153. data() {
  154. return {
  155. checked: false,
  156. formdata: {
  157. username: '',
  158. passwold: '',
  159. },
  160. setbgtf: false,
  161. setTF: false,
  162. value: 'https://web.hnyfwlw.com',
  163. httparr: ['https://web.hnyfwlw.com'],
  164. arrowtf: false,
  165. showA: false,
  166. contentA: '',
  167. isShow: false,
  168. percentNum: 0,
  169. passvalue: false,
  170. turnover: true,
  171. agree: false,
  172. appVersion: '',
  173. };
  174. },
  175. onLoad() {},
  176. onShow() {
  177. // 获取当前 app 版本号
  178. // #ifdef APP-PLUS
  179. this.appVersion = plus.runtime.version;
  180. // #endif
  181. // #ifndef APP-PLUS
  182. this.appVersion = '1.0.0';
  183. // #endif
  184. // 恢复记住的密码
  185. uni.getStorage({
  186. key: 'user_pass',
  187. success: (res) => {
  188. if (res.data) {
  189. this.formdata.passwold = res.data;
  190. this.checked = true;
  191. } else {
  192. this.checked = false;
  193. }
  194. },
  195. });
  196. // 恢复记住的用户名
  197. uni.getStorage({
  198. key: 'user_name',
  199. success: (res) => {
  200. this.formdata.username = res.data;
  201. },
  202. });
  203. // 恢复服务器地址
  204. uni.getStorage({
  205. key: 'http',
  206. success: (res) => {
  207. this.value = res.data;
  208. },
  209. });
  210. console.log(this.value);
  211. uni.getStorage({
  212. key: 'turnover',
  213. success: (res) => {
  214. console.log(res.data);
  215. this.turnover = res.data;
  216. },
  217. });
  218. this.getEquipList();
  219. },
  220. methods: {
  221. // 版本检测
  222. async getEquipList() {
  223. const res = await this.$myRequest({
  224. url: '/api/api_gateway?method=home.homes.app_version_record',
  225. data: {
  226. ret: 'first',
  227. },
  228. });
  229. console.log(res);
  230. this.appName = res[0].app_name;
  231. this.versions = Number(res[0].app_num.match(/\d+/g).join(''));
  232. var id = Number(plus.runtime.version.match(/\d+/g).join(''));
  233. console.log(this.versions, plus.runtime.version);
  234. if (this.percentNum > 0) {
  235. console.log('更新中');
  236. } else {
  237. console.log(this.turnover);
  238. if (this.turnover) {
  239. if (this.versions > id) {
  240. uni.showModal({
  241. title: '检测到有新版本,是否更新?',
  242. content: '建议更新,不更新可能会出现部分数据无法获取!',
  243. confirmText: '更新',
  244. cancelText: '不更新',
  245. success: (res) => {
  246. if (res.confirm) {
  247. console.log('用户点击确定');
  248. this.showA = true;
  249. this.isShow = true;
  250. this.upgrade();
  251. } else if (res.cancel) {
  252. console.log('用户点击取消');
  253. uni.showModal({
  254. title: '是否每次进入提示更新?',
  255. content: '不再提示后可在<我的>-<关于我们>-<版本更新>中更新',
  256. confirmText: '提示',
  257. cancelText: '不再提示',
  258. success: (res) => {
  259. if (res.confirm) {
  260. console.log('用户点击确定');
  261. uni.setStorage({
  262. key: 'turnover',
  263. data: true,
  264. });
  265. } else if (res.cancel) {
  266. uni.setStorage({
  267. key: 'turnover',
  268. data: false,
  269. });
  270. }
  271. },
  272. });
  273. }
  274. },
  275. });
  276. } else {
  277. uni.getStorage({
  278. key: 'session_key',
  279. success: (res) => {
  280. console.log(res);
  281. if (res.data != '') {
  282. uni.switchTab({
  283. url: '../index/index',
  284. });
  285. }
  286. },
  287. });
  288. }
  289. } else {
  290. uni.getStorage({
  291. key: 'session_key',
  292. success: (res) => {
  293. console.log(res);
  294. if (res.data != '') {
  295. uni.switchTab({
  296. url: '../index/index',
  297. });
  298. }
  299. },
  300. });
  301. }
  302. }
  303. },
  304. // 应用升级下载
  305. upgrade() {
  306. console.log(this.appName);
  307. var appName = '';
  308. if (this.$isneutral) {
  309. appName = 'big_data'; // 云飞
  310. } else {
  311. appName = 'big_data2'; // 中性
  312. }
  313. var url = 'https://hnyfwlw.com/app/' + appName + '.apk';
  314. const downloadTask = uni.downloadFile({
  315. url: url,
  316. success: (res) => {
  317. console.log(res);
  318. if (res.statusCode === 200) {
  319. console.log('下载成功');
  320. console.log(
  321. '安装包下载成功,即将安装:' + JSON.stringify(res, null, 4),
  322. );
  323. plus.runtime.openFile(res.tempFilePath);
  324. this.showA = false;
  325. this.isShow = false;
  326. }
  327. },
  328. fail: (err) => {
  329. console.log(err);
  330. },
  331. complete: (com) => {
  332. console.log(com);
  333. },
  334. });
  335. downloadTask.onProgressUpdate((res) => {
  336. this.percentNum = res.progress;
  337. if (res.progress == 100) {
  338. console.log('下载完成了');
  339. }
  340. });
  341. },
  342. // 登录表单提交
  343. async formSubmit() {
  344. // 1. 必填校验:用户名
  345. if (!this.formdata.username || !this.formdata.username.trim()) {
  346. uni.showToast({
  347. title: '请输入账号/手机号',
  348. icon: 'none',
  349. });
  350. return;
  351. }
  352. // 2. 必填校验:密码
  353. if (!this.formdata.passwold) {
  354. uni.showToast({
  355. title: '请输入密码',
  356. icon: 'none',
  357. });
  358. return;
  359. }
  360. // 3. 隐私协议校验
  361. if (!this.agree) {
  362. uni.showToast({
  363. title: '请先阅读并同意用户隐私协议',
  364. icon: 'none',
  365. });
  366. return;
  367. }
  368. // 4. 发起登录请求(仅成功时才继续后续流程)
  369. try {
  370. const res = await this.$myRequest({
  371. url: '/api/api_gateway?method=user.login.login_user',
  372. data: {
  373. username: this.formdata.username,
  374. password: this.formdata.passwold,
  375. },
  376. });
  377. // 兼容:登录接口可能直接返回 session_key,也可能在 data 里
  378. let session_key = res.session_key || (res.data && res.data.session_key);
  379. if (!session_key) {
  380. uni.showToast({
  381. title: res.msg || res.message || '登录失败,请检查账号密码',
  382. icon: 'none',
  383. });
  384. return;
  385. }
  386. // 5. 登录成功,存储 session_key 并跳转
  387. uni.setStorage({
  388. key: 'session_key',
  389. data: session_key,
  390. success: () => {
  391. // 登录前清除可能残留的权限缓存,再用新账号拉取
  392. this.$resetPermissionList();
  393. this.$fetchPermissionList();
  394. uni.switchTab({
  395. url: '../index/index',
  396. });
  397. },
  398. });
  399. } catch (err) {
  400. // 网络错误或接口抛错,提示后不再往下走
  401. console.log('登录请求失败:', err);
  402. uni.showToast({
  403. title: (err && err.message) || '网络异常,请稍后重试',
  404. icon: 'none',
  405. });
  406. }
  407. },
  408. // 密码输入过滤中文
  409. passwoldddata() {
  410. this.formdata.passwold = this.formdata.passwold.replace(
  411. /[\u4E00-\u9FA5]/g,
  412. '',
  413. );
  414. },
  415. // 记住密码
  416. rempass(val) {
  417. this.passvalue = val.value;
  418. if (val.value) {
  419. uni.setStorage({
  420. key: 'user_pass',
  421. data: this.formdata.passwold,
  422. success: function () {
  423. console.log('success');
  424. },
  425. });
  426. }
  427. },
  428. // 用户名失焦保存
  429. blur(val) {
  430. uni.setStorage({
  431. key: 'user_name',
  432. data: val,
  433. success: function () {
  434. console.log('success');
  435. },
  436. });
  437. },
  438. // 长按标题触发设置按钮显示
  439. logoTime() {
  440. this.setTF = true;
  441. },
  442. // 打开设置弹窗
  443. set() {
  444. this.setbgtf = true;
  445. },
  446. // 保存服务器地址设置
  447. sethttp() {
  448. uni.setStorage({
  449. key: 'http',
  450. data: this.value,
  451. success: () => {
  452. this.setbgtf = false;
  453. uni.showToast({
  454. title: '修改成功',
  455. icon: 'none',
  456. });
  457. this.getEquipList();
  458. uni.removeStorage({
  459. key: 'session_key',
  460. });
  461. },
  462. });
  463. },
  464. // 服务器地址下拉展开/收起
  465. arrow() {
  466. this.arrowtf = !this.arrowtf;
  467. },
  468. // 登录时处理记住密码
  469. denglu() {
  470. if (this.passvalue) {
  471. uni.setStorage({
  472. key: 'user_pass',
  473. data: this.formdata.passwold,
  474. success: function () {
  475. console.log('success');
  476. },
  477. });
  478. } else {
  479. uni.removeStorage({
  480. key: 'user_pass',
  481. success: function () {
  482. console.log('success');
  483. },
  484. });
  485. }
  486. },
  487. // 跳转用户隐私协议
  488. goAgreement() {
  489. uni.navigateTo({
  490. url: './agreement',
  491. });
  492. },
  493. },
  494. };
  495. </script>
  496. <style lang="scss" scoped>
  497. /* 页面整体容器 */
  498. .login-container {
  499. height: 100vh;
  500. width: 100%;
  501. background: linear-gradient(180deg, #e8f7ef 0%, #f5f9f6 45%, #ffffff 100%);
  502. position: relative;
  503. overflow: hidden;
  504. box-sizing: border-box;
  505. }
  506. /* 顶部淡绿色渐变背景层 */
  507. .header-bg {
  508. position: absolute;
  509. top: 0;
  510. left: 0;
  511. width: 100%;
  512. height: 420rpx;
  513. background: linear-gradient(180deg, #c8ecdb 0%, #e8f7ef 100%);
  514. z-index: 0;
  515. }
  516. /* Logo 区域 */
  517. .logo-section {
  518. position: relative;
  519. z-index: 1;
  520. display: flex;
  521. flex-direction: column;
  522. align-items: center;
  523. padding-top: 160rpx;
  524. }
  525. /* 绿色圆形 Logo */
  526. .logo-circle {
  527. width: 160rpx;
  528. height: 160rpx;
  529. display: flex;
  530. align-items: center;
  531. justify-content: center;
  532. margin-bottom: 32rpx;
  533. }
  534. /* Logo 内的真实图片 */
  535. .logo-img {
  536. width: 80%;
  537. height: 80%;
  538. }
  539. /* 应用标题 */
  540. .app-title {
  541. font-size: 40rpx;
  542. color: #333333;
  543. font-weight: 500;
  544. letter-spacing: 2rpx;
  545. }
  546. /* 设置按钮 */
  547. .set-btn {
  548. position: absolute;
  549. right: 40rpx;
  550. top: 80rpx;
  551. z-index: 10;
  552. }
  553. /* 登录表单(无卡片,直接平铺) */
  554. .form-card {
  555. position: relative;
  556. z-index: 1;
  557. width: 640rpx;
  558. margin: 72rpx auto 0;
  559. padding: 0 16rpx;
  560. }
  561. /* 表单输入项 */
  562. .form-item {
  563. display: flex;
  564. align-items: center;
  565. border-bottom: 1rpx solid #e5e5e5;
  566. padding: 28rpx 0;
  567. .form-input {
  568. flex: 1;
  569. margin-left: 20rpx;
  570. font-size: 28rpx;
  571. }
  572. ::v-deep .uni-input-input {
  573. color: #333333 !important;
  574. font-size: 28rpx !important;
  575. }
  576. ::v-deep .uicon-eye,
  577. ::v-deep .uicon-eye-off {
  578. color: #bbbbbb !important;
  579. }
  580. }
  581. /* 表单附加项:记住密码 */
  582. .form-extra {
  583. margin-top: 24rpx;
  584. display: flex;
  585. align-items: center;
  586. ::v-deep .u-checkbox__label {
  587. font-size: 26rpx;
  588. color: #666666;
  589. margin-left: 8rpx;
  590. }
  591. ::v-deep .u-checkbox__icon-wrap {
  592. border-color: #cccccc;
  593. }
  594. }
  595. /* 登录按钮 */
  596. .login-btn-wrap {
  597. margin-top: 48rpx;
  598. .login-btn {
  599. width: 100%;
  600. height: 96rpx;
  601. line-height: 96rpx;
  602. background: linear-gradient(135deg, #24b35d 0%, #1a9e4e 100%);
  603. border-radius: 48rpx;
  604. color: #ffffff;
  605. font-size: 32rpx;
  606. font-weight: 500;
  607. border: none;
  608. box-shadow: 0 8rpx 24rpx rgba(36, 179, 93, 0.3);
  609. &::after {
  610. border: none;
  611. }
  612. }
  613. }
  614. /* 用户隐私协议 */
  615. .agreement {
  616. margin-top: 28rpx;
  617. display: flex;
  618. align-items: center;
  619. justify-content: center;
  620. ::v-deep .u-checkbox__label {
  621. font-size: 22rpx;
  622. color: #999999;
  623. margin-left: 4rpx;
  624. }
  625. ::v-deep .u-checkbox__icon-wrap {
  626. border-color: #cccccc;
  627. }
  628. .agree-link {
  629. font-size: 22rpx;
  630. color: #24b35d;
  631. margin-left: 4rpx;
  632. }
  633. }
  634. /* 底部版本号 */
  635. .version-footer {
  636. position: absolute;
  637. bottom: 60rpx;
  638. left: 0;
  639. width: 100%;
  640. text-align: center;
  641. z-index: 1;
  642. .version-text {
  643. font-size: 24rpx;
  644. color: #bbbbbb;
  645. letter-spacing: 4rpx;
  646. }
  647. }
  648. /* 服务器设置弹窗 */
  649. .setbg {
  650. width: 100%;
  651. height: 100vh;
  652. position: absolute;
  653. top: 0;
  654. z-index: 99999;
  655. .mengban {
  656. width: 100%;
  657. height: 100vh;
  658. position: absolute;
  659. top: 0;
  660. background-color: rgba($color: #000000, $alpha: 0.5);
  661. }
  662. .set_http {
  663. position: absolute;
  664. width: 90%;
  665. left: 5%;
  666. top: 30%;
  667. .set_http_top {
  668. display: flex;
  669. justify-content: space-around;
  670. align-items: center;
  671. background-color: #24b35d;
  672. height: 100rpx;
  673. line-height: 100rpx;
  674. color: #ffffff;
  675. border-top-right-radius: 20rpx;
  676. border-top-left-radius: 20rpx;
  677. .set_title {
  678. font-size: 30rpx;
  679. }
  680. }
  681. .set_http_bot {
  682. background-color: #ffffff;
  683. border-bottom-right-radius: 20rpx;
  684. border-bottom-left-radius: 20rpx;
  685. padding: 30rpx;
  686. .set_label {
  687. font-size: 26rpx;
  688. color: #666666;
  689. }
  690. .set_http_bot_input {
  691. margin-top: 20rpx;
  692. border: 2rpx solid #eeeeee;
  693. border-radius: 12rpx;
  694. padding: 16rpx 24rpx;
  695. font-size: 28rpx;
  696. display: flex;
  697. justify-content: space-between;
  698. align-items: center;
  699. input {
  700. width: 90%;
  701. font-size: 28rpx;
  702. }
  703. }
  704. }
  705. .scroll-Y {
  706. border: 2rpx solid #eeeeee;
  707. border-radius: 12rpx;
  708. margin-top: 16rpx;
  709. .scroll-view-item {
  710. padding: 0 20rpx;
  711. height: 70rpx;
  712. font-size: 26rpx;
  713. line-height: 70rpx;
  714. border-bottom: 2rpx solid #f5f5f5;
  715. color: #333333;
  716. }
  717. }
  718. }
  719. }
  720. /* 升级进度框 */
  721. .upgradeBox {
  722. padding: 15rpx;
  723. }
  724. </style>