login.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. <template>
  2. <view id="login-container" class="login-container">
  3. <image class="bgImage" :src="useStore.loginBg" v-if="useStore.loginBg" />
  4. <view class="middle">
  5. <view class="middle-top">
  6. <image class="logo" mode="heightFix" :src="useStore.loginLogo" v-if="useStore.loginLogo" />
  7. <text class="title" :style="{ color: useStore.loginBg ? '#FFFFFF' : '#000000' }" v-if="useStore.loginTitle">{{ useStore.loginTitle }}</text>
  8. </view>
  9. <view class="middle-content">
  10. <text class="title" :style="{ color: useStore.loginBg ? '#FFFFFF' : '#000000' }">请登录</text>
  11. <!-- #ifdef APP-PLUS || MP-WEIXIN -->
  12. <view class="prompt" v-if="!linkUrl">首次账号登录请先配置服务器</view>
  13. <view class="setting" @tap="goSeverConfig"> 配置服务器 </view>
  14. <!--#endif-->
  15. </view>
  16. <view class="middle-input" v-if="switchText == '验证码登录'">
  17. <u-input v-model="phone" prefixIcon="phone" placeholder="请输入手机号" :maxlength="11" :adjustPosition="false" />
  18. <u-input v-model="verify" prefixIcon="email" placeholder="请输入验证码" :maxlength="6" :adjustPosition="false">
  19. <template #suffix>
  20. <button class="verify" @click="getVerifyCode">{{ !useStore.codeTime ? "获取验证码" : useStore.codeTime + "s" }}</button>
  21. </template>
  22. </u-input>
  23. </view>
  24. <view class="middle-input" v-if="switchText == '账号密码登录'">
  25. <u-input type="text" v-model="username" prefixIcon="account" placeholder="请输入账号" :adjustPosition="false" />
  26. <u-input v-model="password" prefixIcon="lock" placeholder="请输入密码" :password="isPassword" :adjustPosition="false">
  27. <template #suffix>
  28. <text :class="!isPassword ? 'iconfont oaIcon-eye' : 'iconfont oaIcon-eye-close'" @click="isPassword = !isPassword"></text>
  29. </template>
  30. </u-input>
  31. </view>
  32. <button class="middle-submit" @click="submitRes">登 录</button>
  33. <!-- #ifdef APP-PLUS || MP-WEIXIN || H5 -->
  34. <view class="middle-switch">
  35. <text class="switch-loginMethod" @click="switchMode(1)">{{ switchText === "验证码登录" ? "账号密码登录" : "验证码登录" }}</text>
  36. <view style="margin: auto"></view>
  37. <text class="switch-register" @click="switchMode(2)">注册账号</text>
  38. </view>
  39. <!--#endif-->
  40. <!-- #ifdef APP-PLUS || MP-WEIXIN -->
  41. <view class="middle-agreed text-center">
  42. <u-checkbox shape="circle" inactiveColor="#0081ff" size="13" :usedAlone="true" :checked="uChecked" @change="uCheckedChange"></u-checkbox>
  43. <!-- <text>登录即已代表阅读并同意</text> -->
  44. <text>我已阅读并同意</text>
  45. <text @click="handleUserAgrement" class="text-blue">用户协议</text>
  46. <text>和</text>
  47. <text @click="handlePrivacy" class="text-blue">隐私政策</text>
  48. </view>
  49. <!--#endif-->
  50. </view>
  51. <view class="bottom">
  52. <div class="title">{{ useStore.loginBottomTitle }}</div>
  53. </view>
  54. </view>
  55. <u-modal :show="modalShow" title="用户协议及隐私政策" :confirmText="'同意'" :cancelText="'不同意'" :zoom="false" :showCancelButton="true" @confirm="modalConfirm()" @cancel="modalShow = false">
  56. <view class="slot-content">
  57. <view>
  58. 您在使用我们的服务时,我们可能会收集和使用您的相关信息。我们希望通过本
  59. <text class="text-blue underline">《用户协议及隐私政策》</text>
  60. 向您说明,在使用我们的服务时,我们如何收集、使用、 储存和分享这些信息,以及我们为您提供的访问、更新、控制和保护这些信息的方式。本
  61. <text @click="handleUserAgrement" class="text-blue underline">《用户协议</text>
  62. <text class="text-blue">及</text>
  63. <text @click="handlePrivacy" class="text-blue underline">隐私政策》</text>,希望您仔细阅读,充分理解协议中的内容后再点击同意。
  64. </view>
  65. </view>
  66. </u-modal>
  67. <u-modal
  68. :show="xunJianStore.modal.show"
  69. title="提醒"
  70. :zoom="false"
  71. :showConfirmButton="true"
  72. :showCancelButton="true"
  73. :closeOnClickOverlay="true"
  74. @confirm="xunJianStore.modalConfirm"
  75. @cancel="xunJianStore.modal.show = false"
  76. @close="xunJianStore.modal.show = false"
  77. >
  78. <view class="slot-content">
  79. <view class="mb20">
  80. <u-input v-model="xunJianStore.modal.exitPassword" placeholder="霸屏退出密码(必填)" border="bottom" style="padding: 6px 0px" />
  81. </view>
  82. </view>
  83. </u-modal>
  84. </template>
  85. <script setup>
  86. /*----------------------------------依赖引入-----------------------------------*/
  87. import { onLoad, onShow, onHide, onLaunch, onReady } from "@dcloudio/uni-app";
  88. import { reactive, getCurrentInstance, toRefs, inject, nextTick } from "vue";
  89. /*----------------------------------接口引入-----------------------------------*/
  90. /*----------------------------------组件引入-----------------------------------*/
  91. /*----------------------------------store引入-----------------------------------*/
  92. import { useStores, commonStores, xunJianStores } from "@/store/modules/index";
  93. /*----------------------------------公共方法引入-----------------------------------*/
  94. import config from "@/config";
  95. import { storageSystem } from "@/utils/storage";
  96. /*----------------------------------公共变量-----------------------------------*/
  97. const { proxy } = getCurrentInstance();
  98. const useStore = useStores();
  99. const commonStore = commonStores();
  100. const xunJianStore = xunJianStores();
  101. /*----------------------------------变量声明-----------------------------------*/
  102. const state = reactive({
  103. /** login数据 */
  104. phone: undefined,
  105. verify: undefined,
  106. switchText: "验证码登录",
  107. username: undefined,
  108. password: undefined,
  109. isPassword: true,
  110. /** 服务器配置数据 */
  111. linkUrl: uni.getStorageSync("serveUrl"),
  112. /** 用户隐私协议数据 */
  113. uChecked: false,
  114. modalShow: false,
  115. });
  116. const { phone, verify, switchText, username, password, isPassword, linkUrl, uChecked, modalShow } = toRefs(state);
  117. /**
  118. * @跳转服务器配置
  119. */
  120. function goSeverConfig() {
  121. proxy.$tab.navigateTo("/pages/serveConfigSelect");
  122. }
  123. /**
  124. * @登录方式切换
  125. */
  126. function switchMode(value) {
  127. if (value == 1) {
  128. switchText.value = switchText.value == "验证码登录" ? "账号密码登录" : "验证码登录";
  129. if (switchText.value == "验证码登录") {
  130. phone.value = username.value;
  131. } else {
  132. username.value = phone.value;
  133. }
  134. } else if (value == 2) {
  135. proxy.$tab.navigateTo("/pages/register");
  136. }
  137. }
  138. /**
  139. * @点击发送验证码
  140. */
  141. function getVerifyCode() {
  142. //#ifdef APP-PLUS || MP-WEIXIN
  143. if (!uni.getStorageSync("serveUrl")) {
  144. proxy.$modal.msg("首次账号登录请先配置服务器");
  145. return;
  146. }
  147. //#endif
  148. verify.value = undefined;
  149. useStore.GetCodeImg({
  150. phone: phone.value,
  151. success: (res) => {
  152. proxy.$modal.msgSuccess("发送成功");
  153. },
  154. });
  155. }
  156. /**
  157. * @初始化
  158. */
  159. function init() {
  160. useStore.SetInterval("codeTime"); //调用倒计时定时器
  161. //#ifdef H5
  162. useStore.GetWxOpenId(1); //调用获取微信公众号openId
  163. if (window.location.host) {
  164. linkUrl.value = window.location.host;
  165. // linkUrl.value = "172.16.120.165:13200";
  166. // linkUrl.value = "localhost:81";
  167. useStore.GetMobileTenantConfig({ url: linkUrl.value });
  168. }
  169. //#endif
  170. //#ifdef APP-PLUS || MP-WEIXIN
  171. if (uni.getStorageSync("serveUrl")) {
  172. linkUrl.value = uni.getStorageSync("serveUrl");
  173. // linkUrl.value = "localhost:81";
  174. useStore.GetMobileTenantConfig({ url: linkUrl.value });
  175. } else {
  176. uni.setStorageSync("serveUrl", "manager.usky.cn");
  177. commonStore.setServeList("manager.usky.cn", "");
  178. linkUrl.value = uni.getStorageSync("serveUrl");
  179. // linkUrl.value = "localhost:81";
  180. useStore.GetMobileTenantConfig({ url: linkUrl.value });
  181. }
  182. //#endif
  183. }
  184. /** 点击提交按钮 */
  185. function submitRes() {
  186. //#ifdef APP-PLUS || MP-WEIXIN
  187. if (!uni.getStorageSync("serveUrl")) {
  188. proxy.$modal.msg("首次登录请先进行服务器配置");
  189. return;
  190. }
  191. if (!uChecked.value) {
  192. modalShow.value = true;
  193. return;
  194. }
  195. //#endif
  196. if (switchText.value == "验证码登录") {
  197. if (!phone.value) {
  198. proxy.$modal.msg("请输入手机号");
  199. return;
  200. }
  201. if (!/^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/.test(phone.value)) {
  202. proxy.$modal.msg("请输入正确的手机号");
  203. return;
  204. }
  205. if (!verify.value) {
  206. proxy.$modal.msg("请输入验证码");
  207. return;
  208. }
  209. } else {
  210. if (!username.value) {
  211. proxy.$modal.msg("请输入账户");
  212. return;
  213. }
  214. if (!password.value) {
  215. proxy.$modal.msg("请输入密码");
  216. return;
  217. }
  218. }
  219. login({
  220. username: state.switchText == "账号密码登录" ? state.username : undefined,
  221. password: state.switchText == "账号密码登录" ? state.password : undefined,
  222. phone: state.switchText == "验证码登录" ? state.phone : undefined,
  223. verify: state.switchText == "验证码登录" ? state.verify : undefined,
  224. tenantId: useStore.tenantId,
  225. cids: proxy.$settingStore.pushClientId || undefined,
  226. type: proxy.$common.isWechatMp() ? "wx" : "app",
  227. openId: proxy.$common.isWechatMp() ? localStorage.getItem("wxOpenId") : undefined,
  228. });
  229. }
  230. /** 获取登录数据 */
  231. function login(data) {
  232. proxy.$modal.loading("登录中,请耐心等待...");
  233. useStore.Login(data).then(() => {
  234. /** 获取用户信息 */
  235. proxy.$modal.closeLoading();
  236. useStore.GetInfo().then((res) => {
  237. proxy.$tab.reLaunch("/pages/index");
  238. proxy.$settingStore.initThemeColor(storageSystem.get("themeColor")); //初始化默认主题
  239. });
  240. });
  241. }
  242. /** 隐私弹窗确定事件 */
  243. function modalConfirm() {
  244. state.uChecked = true;
  245. state.modalShow = false;
  246. setTimeout(() => {
  247. submitRes();
  248. });
  249. }
  250. // 复选框chage事件
  251. function uCheckedChange(e) {
  252. state.uChecked = e;
  253. }
  254. // 用户协议
  255. function handleUserAgrement() {
  256. let site = config.appInfo.agreements[0];
  257. proxy.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
  258. }
  259. // 隐私协议
  260. function handlePrivacy() {
  261. let site = config.appInfo.agreements[1];
  262. proxy.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
  263. }
  264. onShow(() => {
  265. nextTick(() => {
  266. init();
  267. });
  268. });
  269. onLoad((options) => {});
  270. </script>
  271. <style lang="scss" scoped>
  272. :deep() {
  273. .u-modal {
  274. .slot-content {
  275. font-size: 16px;
  276. width: 100%;
  277. }
  278. }
  279. }
  280. .login-container {
  281. position: fixed;
  282. top: 0;
  283. left: 0;
  284. right: 0;
  285. bottom: 0;
  286. display: flex;
  287. width: 100%;
  288. height: 100vh;
  289. background-color: $uni-bg-color;
  290. .bgImage {
  291. position: fixed;
  292. top: 0;
  293. left: 0;
  294. right: 0;
  295. z-index: 0;
  296. width: 100%;
  297. height: 100%;
  298. }
  299. .middle {
  300. position: relative;
  301. z-index: 1;
  302. width: 100%;
  303. padding: 0 30px;
  304. margin: auto;
  305. margin-top: 30%;
  306. &-top {
  307. display: flex;
  308. align-items: center;
  309. justify-content: center;
  310. margin-bottom: 60px;
  311. .logo {
  312. height: 40px;
  313. width: auto;
  314. margin-right: 10px;
  315. }
  316. .title {
  317. font-size: 20px;
  318. color: #000;
  319. max-width: 50%;
  320. // white-space: nowrap;
  321. // overflow: hidden; //超出的文本隐藏
  322. // text-overflow: ellipsis; //溢出用省略号显示
  323. }
  324. }
  325. &-content {
  326. display: flex;
  327. position: relative;
  328. margin: 30px 0 30px 0;
  329. .title {
  330. margin: auto auto auto 0;
  331. color: #000;
  332. font-size: 18px;
  333. }
  334. .setting {
  335. color: #2a98ff;
  336. margin: auto 0;
  337. }
  338. .prompt {
  339. position: absolute;
  340. top: -35px;
  341. right: 0px;
  342. background-color: #2a98ff;
  343. text-align: center;
  344. line-height: 25px;
  345. display: inline-block;
  346. color: #fff;
  347. padding: 3px 5px;
  348. border-radius: 3px;
  349. &::after {
  350. content: "";
  351. position: absolute;
  352. border: 5px solid transparent;
  353. transform: rotate(90deg);
  354. right: 5px;
  355. bottom: -9px;
  356. border-left-color: #2a98ff;
  357. }
  358. }
  359. }
  360. // 登录页-服务器配置样式 开始
  361. &-input {
  362. :deep() {
  363. .u-input {
  364. height: 45px;
  365. border: 0 !important;
  366. border-radius: 8px;
  367. margin-bottom: 15px;
  368. padding: 5px 12px !important;
  369. background-color: #f5f6fa !important;
  370. }
  371. .input-placeholder {
  372. color: #c0c4cc !important;
  373. }
  374. .uni-input-wrapper {
  375. font-size: 16px;
  376. }
  377. .u-icon__icon {
  378. font-size: 24px !important;
  379. line-height: 24px !important;
  380. color: gray !important;
  381. }
  382. .iconfont {
  383. color: gray !important;
  384. }
  385. :-webkit-autofill {
  386. caret-color: #000; // 设置光标颜色
  387. // -webkit-text-fill-color: gray !important;
  388. -webkit-box-shadow: 0 0 0px 1000px transparent inset !important;
  389. background-color: transparent;
  390. background-image: none;
  391. transition: background-color 50000s ease-in-out 0s; //背景色透明 生效时长 过渡效果 启用时延迟的时间
  392. }
  393. }
  394. }
  395. &-switch {
  396. width: 100%;
  397. display: flex;
  398. margin-top: 20px;
  399. color: #96a6b5;
  400. &-loginMethod {
  401. display: block;
  402. }
  403. &-register {
  404. display: block;
  405. }
  406. }
  407. &-submit {
  408. height: 45px;
  409. line-height: 45px;
  410. border-radius: 24px;
  411. background: #2a98ff;
  412. color: #fff;
  413. border: 0px;
  414. }
  415. &-agreed {
  416. color: #96a6b5;
  417. margin-top: 30px;
  418. display: flex;
  419. flex-wrap: wrap;
  420. justify-content: center;
  421. > uni-view {
  422. margin: auto 0;
  423. }
  424. > uni-text {
  425. margin: auto 0;
  426. }
  427. // animation: roundRule 0.5s linear infinite;
  428. }
  429. @keyframes roundRule {
  430. 0% {
  431. transform: translateX(0);
  432. }
  433. 50% {
  434. transform: translateX(-5px);
  435. }
  436. 100% {
  437. transform: translateX(0);
  438. }
  439. }
  440. }
  441. .bottom {
  442. position: fixed;
  443. width: 100%;
  444. bottom: 20px;
  445. .title {
  446. text-align: center;
  447. color: #96a6b5;
  448. font-size: 14px;
  449. }
  450. }
  451. }
  452. @media (min-width: 1280px) {
  453. .middle {
  454. margin-top: auto !important;
  455. }
  456. }
  457. </style>