login.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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('安装包下载成功,即将安装:' + res.tempFilePath);
  324. // 调起系统安装器安装 apk(需在系统设置中允许本应用“安装未知应用”)
  325. plus.runtime.install(
  326. res.tempFilePath,
  327. { force: false },
  328. () => {
  329. console.log('已调起安装');
  330. },
  331. (e) => {
  332. console.log('安装失败:', e);
  333. uni.showModal({
  334. title: '安装失败',
  335. content:
  336. '请在系统设置中允许本应用“安装未知应用”权限后重试',
  337. showCancel: false,
  338. });
  339. },
  340. );
  341. this.showA = false;
  342. this.isShow = false;
  343. }
  344. },
  345. fail: (err) => {
  346. console.log(err);
  347. },
  348. complete: (com) => {
  349. console.log(com);
  350. },
  351. });
  352. downloadTask.onProgressUpdate((res) => {
  353. this.percentNum = res.progress;
  354. if (res.progress == 100) {
  355. console.log('下载完成了');
  356. }
  357. });
  358. },
  359. // 登录表单提交
  360. async formSubmit() {
  361. // 1. 必填校验:用户名
  362. if (!this.formdata.username || !this.formdata.username.trim()) {
  363. uni.showToast({
  364. title: '请输入账号/手机号',
  365. icon: 'none',
  366. });
  367. return;
  368. }
  369. // 2. 必填校验:密码
  370. if (!this.formdata.passwold) {
  371. uni.showToast({
  372. title: '请输入密码',
  373. icon: 'none',
  374. });
  375. return;
  376. }
  377. // 3. 隐私协议校验
  378. if (!this.agree) {
  379. uni.showToast({
  380. title: '请先阅读并同意用户隐私协议',
  381. icon: 'none',
  382. });
  383. return;
  384. }
  385. // 4. 发起登录请求(仅成功时才继续后续流程)
  386. try {
  387. const res = await this.$myRequest({
  388. url: '/api/api_gateway?method=user.login.login_user',
  389. data: {
  390. username: this.formdata.username,
  391. password: this.formdata.passwold,
  392. },
  393. });
  394. // 兼容:登录接口可能直接返回 session_key,也可能在 data 里
  395. let session_key = res.session_key || (res.data && res.data.session_key);
  396. if (!session_key) {
  397. uni.showToast({
  398. title: res.msg || res.message || '登录失败,请检查账号密码',
  399. icon: 'none',
  400. });
  401. return;
  402. }
  403. // 5. 登录成功,存储 session_key 并跳转
  404. uni.setStorage({
  405. key: 'session_key',
  406. data: session_key,
  407. success: () => {
  408. // 登录前清除可能残留的权限缓存,再用新账号拉取
  409. this.$resetPermissionList();
  410. this.$fetchPermissionList();
  411. uni.switchTab({
  412. url: '../index/index',
  413. });
  414. },
  415. });
  416. } catch (err) {
  417. // 网络错误或接口抛错,提示后不再往下走
  418. console.log('登录请求失败:', err);
  419. uni.showToast({
  420. title: (err && err.message) || '网络异常,请稍后重试',
  421. icon: 'none',
  422. });
  423. }
  424. },
  425. // 密码输入过滤中文
  426. passwoldddata() {
  427. this.formdata.passwold = this.formdata.passwold.replace(
  428. /[\u4E00-\u9FA5]/g,
  429. '',
  430. );
  431. },
  432. // 记住密码
  433. rempass(val) {
  434. this.passvalue = val.value;
  435. if (val.value) {
  436. uni.setStorage({
  437. key: 'user_pass',
  438. data: this.formdata.passwold,
  439. success: function () {
  440. console.log('success');
  441. },
  442. });
  443. }
  444. },
  445. // 用户名失焦保存
  446. blur(val) {
  447. uni.setStorage({
  448. key: 'user_name',
  449. data: val,
  450. success: function () {
  451. console.log('success');
  452. },
  453. });
  454. },
  455. // 长按标题触发设置按钮显示
  456. logoTime() {
  457. this.setTF = true;
  458. },
  459. // 打开设置弹窗
  460. set() {
  461. this.setbgtf = true;
  462. },
  463. // 保存服务器地址设置
  464. sethttp() {
  465. uni.setStorage({
  466. key: 'http',
  467. data: this.value,
  468. success: () => {
  469. this.setbgtf = false;
  470. uni.showToast({
  471. title: '修改成功',
  472. icon: 'none',
  473. });
  474. this.getEquipList();
  475. uni.removeStorage({
  476. key: 'session_key',
  477. });
  478. },
  479. });
  480. },
  481. // 服务器地址下拉展开/收起
  482. arrow() {
  483. this.arrowtf = !this.arrowtf;
  484. },
  485. // 登录时处理记住密码
  486. denglu() {
  487. if (this.passvalue) {
  488. uni.setStorage({
  489. key: 'user_pass',
  490. data: this.formdata.passwold,
  491. success: function () {
  492. console.log('success');
  493. },
  494. });
  495. } else {
  496. uni.removeStorage({
  497. key: 'user_pass',
  498. success: function () {
  499. console.log('success');
  500. },
  501. });
  502. }
  503. },
  504. // 跳转用户隐私协议
  505. goAgreement() {
  506. uni.navigateTo({
  507. url: './agreement',
  508. });
  509. },
  510. },
  511. };
  512. </script>
  513. <style lang="scss" scoped>
  514. /* 页面整体容器 */
  515. .login-container {
  516. height: 100vh;
  517. width: 100%;
  518. background: linear-gradient(180deg, #d1f2e8 6.77%, #fff 28.02%);
  519. position: relative;
  520. overflow: hidden;
  521. box-sizing: border-box;
  522. }
  523. /* 顶部淡绿色渐变背景层 */
  524. .header-bg {
  525. position: absolute;
  526. top: 0;
  527. left: 0;
  528. width: 100%;
  529. height: 420rpx;
  530. z-index: 0;
  531. }
  532. /* Logo 区域 */
  533. .logo-section {
  534. position: relative;
  535. z-index: 1;
  536. display: flex;
  537. flex-direction: column;
  538. align-items: center;
  539. padding-top: 160rpx;
  540. }
  541. /* 绿色圆形 Logo */
  542. .logo-circle {
  543. width: 160rpx;
  544. height: 160rpx;
  545. display: flex;
  546. align-items: center;
  547. justify-content: center;
  548. margin-bottom: 32rpx;
  549. }
  550. /* Logo 内的真实图片 */
  551. .logo-img {
  552. width: 80%;
  553. height: 80%;
  554. }
  555. /* 应用标题 */
  556. .app-title {
  557. font-size: 40rpx;
  558. color: #333333;
  559. font-weight: 500;
  560. letter-spacing: 2rpx;
  561. }
  562. /* 设置按钮 */
  563. .set-btn {
  564. position: absolute;
  565. right: 40rpx;
  566. top: 80rpx;
  567. z-index: 10;
  568. }
  569. /* 登录表单(无卡片,直接平铺) */
  570. .form-card {
  571. position: relative;
  572. z-index: 1;
  573. width: 640rpx;
  574. margin: 72rpx auto 0;
  575. padding: 0 16rpx;
  576. }
  577. /* 表单输入项 */
  578. .form-item {
  579. display: flex;
  580. align-items: center;
  581. border-bottom: 1rpx solid #e5e5e5;
  582. padding: 28rpx 0;
  583. .form-input {
  584. flex: 1;
  585. margin-left: 20rpx;
  586. font-size: 28rpx;
  587. }
  588. ::v-deep .uni-input-input {
  589. color: #333333 !important;
  590. font-size: 28rpx !important;
  591. }
  592. ::v-deep .uicon-eye,
  593. ::v-deep .uicon-eye-off {
  594. color: #bbbbbb !important;
  595. }
  596. }
  597. /* 表单附加项:记住密码 */
  598. .form-extra {
  599. margin-top: 24rpx;
  600. display: flex;
  601. align-items: center;
  602. ::v-deep .u-checkbox__label {
  603. font-size: 26rpx;
  604. color: #666666;
  605. margin-left: 8rpx;
  606. }
  607. ::v-deep .u-checkbox__icon-wrap {
  608. border-color: #cccccc;
  609. }
  610. }
  611. /* 登录按钮 */
  612. .login-btn-wrap {
  613. margin-top: 48rpx;
  614. .login-btn {
  615. width: 100%;
  616. height: 96rpx;
  617. line-height: 96rpx;
  618. background: linear-gradient(135deg, #24b35d 0%, #1a9e4e 100%);
  619. border-radius: 48rpx;
  620. color: #ffffff;
  621. font-size: 32rpx;
  622. font-weight: 500;
  623. border: none;
  624. box-shadow: 0 8rpx 24rpx rgba(36, 179, 93, 0.3);
  625. &::after {
  626. border: none;
  627. }
  628. }
  629. }
  630. /* 用户隐私协议 */
  631. .agreement {
  632. margin-top: 28rpx;
  633. display: flex;
  634. align-items: center;
  635. justify-content: center;
  636. ::v-deep .u-checkbox__label {
  637. font-size: 22rpx;
  638. color: #999999;
  639. margin-left: 4rpx;
  640. }
  641. ::v-deep .u-checkbox__icon-wrap {
  642. border-color: #cccccc;
  643. }
  644. .agree-link {
  645. font-size: 22rpx;
  646. color: #24b35d;
  647. margin-left: 4rpx;
  648. }
  649. }
  650. /* 底部版本号 */
  651. .version-footer {
  652. position: absolute;
  653. bottom: 60rpx;
  654. left: 0;
  655. width: 100%;
  656. text-align: center;
  657. z-index: 1;
  658. .version-text {
  659. font-size: 24rpx;
  660. color: #bbbbbb;
  661. letter-spacing: 4rpx;
  662. }
  663. }
  664. /* 服务器设置弹窗 */
  665. .setbg {
  666. width: 100%;
  667. height: 100vh;
  668. position: absolute;
  669. top: 0;
  670. z-index: 99999;
  671. .mengban {
  672. width: 100%;
  673. height: 100vh;
  674. position: absolute;
  675. top: 0;
  676. background-color: rgba($color: #000000, $alpha: 0.5);
  677. }
  678. .set_http {
  679. position: absolute;
  680. width: 90%;
  681. left: 5%;
  682. top: 30%;
  683. .set_http_top {
  684. display: flex;
  685. justify-content: space-around;
  686. align-items: center;
  687. background-color: #24b35d;
  688. height: 100rpx;
  689. line-height: 100rpx;
  690. color: #ffffff;
  691. border-top-right-radius: 20rpx;
  692. border-top-left-radius: 20rpx;
  693. .set_title {
  694. font-size: 30rpx;
  695. }
  696. }
  697. .set_http_bot {
  698. background-color: #ffffff;
  699. border-bottom-right-radius: 20rpx;
  700. border-bottom-left-radius: 20rpx;
  701. padding: 30rpx;
  702. .set_label {
  703. font-size: 26rpx;
  704. color: #666666;
  705. }
  706. .set_http_bot_input {
  707. margin-top: 20rpx;
  708. border: 2rpx solid #eeeeee;
  709. border-radius: 12rpx;
  710. padding: 16rpx 24rpx;
  711. font-size: 28rpx;
  712. display: flex;
  713. justify-content: space-between;
  714. align-items: center;
  715. input {
  716. width: 90%;
  717. font-size: 28rpx;
  718. }
  719. }
  720. }
  721. .scroll-Y {
  722. border: 2rpx solid #eeeeee;
  723. border-radius: 12rpx;
  724. margin-top: 16rpx;
  725. .scroll-view-item {
  726. padding: 0 20rpx;
  727. height: 70rpx;
  728. font-size: 26rpx;
  729. line-height: 70rpx;
  730. border-bottom: 2rpx solid #f5f5f5;
  731. color: #333333;
  732. }
  733. }
  734. }
  735. }
  736. /* 升级进度框 */
  737. .upgradeBox {
  738. padding: 15rpx;
  739. }
  740. ::v-deep .u-flex {
  741. display: flex;
  742. align-items: center;
  743. }
  744. </style>