login.vue 19 KB

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