login.vue 13 KB

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