login.vue 13 KB

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