login.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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 type="number" 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)" v-if="config.appInfo.appid != '__UNI__BF1A1F0'">注册账号</text>
  38. </view>
  39. <!--#endif-->
  40. <!-- #ifdef APP-PLUS || MP-WEIXIN -->
  41. <view class="middle-agreed text-center" v-if="config.appInfo.appid != '__UNI__BF1A1F0'">
  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.indexOf("localhost") != -1) {
  164. useStore.GetMobileTenantConfig({ url: linkUrl.value });
  165. // useStore.GetMobileTenantConfig({ url: "manager.usky.cn" });
  166. } else {
  167. linkUrl.value = window.location.host;
  168. useStore.GetMobileTenantConfig({ url: linkUrl.value });
  169. }
  170. //#endif
  171. //#ifdef APP-PLUS || MP-WEIXIN
  172. if (uni.getStorageSync("serveUrl")) {
  173. linkUrl.value = uni.getStorageSync("serveUrl");
  174. useStore.GetMobileTenantConfig({ url: linkUrl.value });
  175. } else {
  176. if (config.appInfo.appid == "__UNI__BF1A1F0") {
  177. uni.setStorageSync("serveUrl", "120.26.164.249:13212");
  178. commonStore.setServeList("120.26.164.249:13212", "");
  179. } else {
  180. uni.setStorageSync("serveUrl", "manager.usky.cn");
  181. commonStore.setServeList("manager.usky.cn", "");
  182. }
  183. linkUrl.value = uni.getStorageSync("serveUrl");
  184. useStore.GetMobileTenantConfig({ url: linkUrl.value });
  185. }
  186. //#endif
  187. }
  188. /** 点击提交按钮 */
  189. function submitRes() {
  190. //#ifdef APP-PLUS || MP-WEIXIN
  191. if (!uni.getStorageSync("serveUrl")) {
  192. proxy.$modal.msg("首次登录请先进行服务器配置");
  193. return;
  194. }
  195. if (config.appInfo.appid != "__UNI__BF1A1F0" && !uChecked.value) {
  196. modalShow.value = true;
  197. return;
  198. }
  199. //#endif
  200. if (switchText.value == "验证码登录") {
  201. if (!phone.value) {
  202. proxy.$modal.msg("请输入手机号");
  203. return;
  204. }
  205. 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)) {
  206. proxy.$modal.msg("请输入正确的手机号");
  207. return;
  208. }
  209. if (!verify.value) {
  210. proxy.$modal.msg("请输入验证码");
  211. return;
  212. }
  213. } else {
  214. if (!username.value) {
  215. proxy.$modal.msg("请输入账户");
  216. return;
  217. }
  218. if (!password.value) {
  219. proxy.$modal.msg("请输入密码");
  220. return;
  221. }
  222. }
  223. login({
  224. username: state.switchText == "账号密码登录" ? state.username : undefined,
  225. password: state.switchText == "账号密码登录" ? state.password : undefined,
  226. phone: state.switchText == "验证码登录" ? state.phone : undefined,
  227. verify: state.switchText == "验证码登录" ? state.verify : undefined,
  228. tenantId: useStore.tenantId,
  229. cids: proxy.$settingStore.pushClientId || undefined,
  230. type: proxy.$common.isWechatMp() ? "wx" : "app",
  231. openId: proxy.$common.isWechatMp() ? localStorage.getItem("wxOpenId") : undefined,
  232. });
  233. }
  234. /** 获取登录数据 */
  235. function login(data) {
  236. proxy.$modal.loading( "登录中,请耐心等待...");
  237. useStore.Login(data).then(() => {
  238. /** 获取用户信息 */
  239. proxy.$modal.closeLoading();
  240. useStore.GetInfo().then((res) => {
  241. proxy.$tab.reLaunch("/pages/index");
  242. proxy.$settingStore.initThemeColor(storageSystem.get("themeColor")); //初始化默认主题
  243. });
  244. });
  245. }
  246. /** 隐私弹窗确定事件 */
  247. function modalConfirm() {
  248. state.uChecked = true;
  249. state.modalShow = false;
  250. setTimeout(() => {
  251. submitRes();
  252. });
  253. }
  254. // 复选框chage事件
  255. function uCheckedChange(e) {
  256. state.uChecked = e;
  257. }
  258. // 用户协议
  259. function handleUserAgrement() {
  260. let site = config.appInfo.agreements[0];
  261. proxy.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
  262. }
  263. // 隐私协议
  264. function handlePrivacy() {
  265. let site = config.appInfo.agreements[1];
  266. proxy.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
  267. }
  268. onShow(() => {
  269. init();
  270. });
  271. </script>
  272. <style lang="scss" scoped>
  273. :deep() {
  274. .u-modal {
  275. .slot-content {
  276. font-size: 16px;
  277. width: 100%;
  278. }
  279. }
  280. }
  281. .login-container {
  282. position: fixed;
  283. top: 0;
  284. left: 0;
  285. right: 0;
  286. bottom: 0;
  287. display: flex;
  288. width: 100%;
  289. height: 100vh;
  290. background-color: $uni-bg-color;
  291. .bgImage {
  292. position: fixed;
  293. top: 0;
  294. left: 0;
  295. right: 0;
  296. z-index: 0;
  297. width: 100%;
  298. height: 100%;
  299. }
  300. .middle {
  301. position: relative;
  302. z-index: 1;
  303. width: 100%;
  304. padding: 0 30px;
  305. margin: auto;
  306. margin-top: 30%;
  307. &-top {
  308. display: flex;
  309. align-items: center;
  310. justify-content: center;
  311. margin-bottom: 60px;
  312. .logo {
  313. height: 40px;
  314. width: auto;
  315. margin-right: 10px;
  316. }
  317. .title {
  318. font-size: 20px;
  319. color: #000;
  320. max-width: 50%;
  321. // white-space: nowrap;
  322. // overflow: hidden; //超出的文本隐藏
  323. // text-overflow: ellipsis; //溢出用省略号显示
  324. }
  325. }
  326. &-content {
  327. display: flex;
  328. position: relative;
  329. margin: 30px 0 30px 0;
  330. .title {
  331. margin: auto auto auto 0;
  332. color: #000;
  333. font-size: 18px;
  334. }
  335. .setting {
  336. color: #2a98ff;
  337. margin: auto 0;
  338. }
  339. .prompt {
  340. position: absolute;
  341. top: -35px;
  342. right: 0px;
  343. background-color: #2a98ff;
  344. text-align: center;
  345. line-height: 25px;
  346. display: inline-block;
  347. color: #fff;
  348. padding: 3px 5px;
  349. border-radius: 3px;
  350. &::after {
  351. content: "";
  352. position: absolute;
  353. border: 5px solid transparent;
  354. transform: rotate(90deg);
  355. right: 5px;
  356. bottom: -9px;
  357. border-left-color: #2a98ff;
  358. }
  359. }
  360. }
  361. // 登录页-服务器配置样式 开始
  362. &-input {
  363. :deep() {
  364. .u-input {
  365. height: 45px;
  366. border: 0 !important;
  367. border-radius: 8px;
  368. margin-bottom: 15px;
  369. padding: 5px 12px !important;
  370. background-color: #f5f6fa !important;
  371. }
  372. .input-placeholder {
  373. color: #c0c4cc !important;
  374. }
  375. .uni-input-wrapper {
  376. font-size: 16px;
  377. }
  378. .u-icon__icon {
  379. font-size: 24px !important;
  380. line-height: 24px !important;
  381. color: gray !important;
  382. }
  383. .iconfont {
  384. color: gray !important;
  385. }
  386. :-webkit-autofill {
  387. caret-color: #000; // 设置光标颜色
  388. // -webkit-text-fill-color: gray !important;
  389. -webkit-box-shadow: 0 0 0px 1000px transparent inset !important;
  390. background-color: transparent;
  391. background-image: none;
  392. transition: background-color 50000s ease-in-out 0s; //背景色透明 生效时长 过渡效果 启用时延迟的时间
  393. }
  394. }
  395. }
  396. &-switch {
  397. width: 100%;
  398. display: flex;
  399. margin-top: 20px;
  400. color: #96a6b5;
  401. &-loginMethod {
  402. display: block;
  403. }
  404. &-register {
  405. display: block;
  406. }
  407. }
  408. &-submit {
  409. height: 45px;
  410. line-height: 45px;
  411. border-radius: 24px;
  412. background: #2a98ff;
  413. color: #fff;
  414. border: 0px;
  415. }
  416. &-agreed {
  417. color: #96a6b5;
  418. margin-top: 30px;
  419. display: flex;
  420. flex-wrap: wrap;
  421. justify-content: center;
  422. > uni-view {
  423. margin: auto 0;
  424. }
  425. > uni-text {
  426. margin: auto 0;
  427. }
  428. // animation: roundRule 0.5s linear infinite;
  429. }
  430. @keyframes roundRule {
  431. 0% {
  432. transform: translateX(0);
  433. }
  434. 50% {
  435. transform: translateX(-5px);
  436. }
  437. 100% {
  438. transform: translateX(0);
  439. }
  440. }
  441. }
  442. .bottom {
  443. position: fixed;
  444. width: 100%;
  445. bottom: 20px;
  446. .title {
  447. text-align: center;
  448. color: #96a6b5;
  449. font-size: 14px;
  450. }
  451. }
  452. }
  453. @media (min-width: 1280px) {
  454. .middle {
  455. margin-top: auto !important;
  456. }
  457. }
  458. </style>