login.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <template>
  2. <view id="login-container" class="login-container">
  3. <image class="bgImage" :src="useStore.$state.loginBg" v-if="useStore.$state.loginBg" />
  4. <view class="middle">
  5. <view class="middle-top">
  6. <image class="logo" mode="heightFix" :src="useStore.$state.loginLogo" v-if="useStore.$state.loginLogo" />
  7. <text class="title" :style="{ color: useStore.$state.loginBg ? '#FFFFFF' : '#000000' }" v-if="useStore.$state.loginTitle">{{ useStore.$state.loginTitle }}</text>
  8. </view>
  9. <view class="middle-content">
  10. <text class="title" :style="{ color: useStore.$state.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="请输入手机号" />
  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="inputIconBool">
  27. <template #suffix>
  28. <text :class="!inputIconBool ? 'iconfont ucicon-eye' : 'iconfont ucicon-eye-close'" @click="inputIconBool = !inputIconBool"></text>
  29. </template>
  30. </u-input>
  31. </view>
  32. <button class="middle-submit" @click="submitRes">登 录</button>
  33. <view class="middle-switch">
  34. <text class="switch-loginMethod" @click="switchMode(1)">{{ switchText }}</text>
  35. <div style="margin: auto"></div>
  36. <text class="switch-register" @click="switchMode(2)">注册账号</text>
  37. </view>
  38. <!-- #ifdef APP-PLUS || MP-WEIXIN -->
  39. <view class="middle-agreed text-center">
  40. <u-checkbox-group v-model="userChecked">
  41. <u-checkbox :name="true" shape="circle" inactiveColor="#0081ff" size="13"></u-checkbox>
  42. </u-checkbox-group>
  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.$state.loginBottomTitle }}</div>
  53. </view>
  54. </view>
  55. </template>
  56. <script setup>
  57. import config from "@/config";
  58. import { onLoad, onShow, onHide, onLaunch, onReady } from "@dcloudio/uni-app";
  59. import { reactive, getCurrentInstance, toRefs, inject } from "vue";
  60. import { publicStores, useStores } from "@/store/modules/index";
  61. const useStore = useStores();
  62. const publicStore = publicStores();
  63. const { proxy } = getCurrentInstance();
  64. const data = reactive({
  65. /** login数据 */
  66. phone: undefined,
  67. verify: undefined,
  68. switchText: "验证码登录",
  69. username: undefined,
  70. password: undefined,
  71. inputIconBool: true,
  72. /** 服务器配置数据 */
  73. linkUrl: uni.getStorageSync("serveUrl"),
  74. /** 用户隐私协议数据 */
  75. userChecked: [true],
  76. });
  77. const { phone, verify, switchText, username, password, inputIconBool, linkUrl, userChecked } = toRefs(data);
  78. /**
  79. * @跳转服务器配置
  80. */
  81. function goSeverConfig() {
  82. proxy.$tab.navigateTo("/pages/serveConfigSelect");
  83. }
  84. /**
  85. * @登录方式切换
  86. */
  87. function switchMode(value) {
  88. if (value == 1) {
  89. switchText.value == "验证码登录" ? (switchText.value = "账号密码登录") : (switchText.value = "验证码登录");
  90. } else if (value == 2) {
  91. proxy.$tab.navigateTo("/pages/register");
  92. }
  93. }
  94. /**
  95. * @点击发送验证码
  96. */
  97. function getVerifyCode() {
  98. //#ifdef APP-PLUS || MP-WEIXIN
  99. if (!uni.getStorageSync("serveUrl")) {
  100. proxy.$modal.msg("首次账号登录请先配置服务器");
  101. return;
  102. }
  103. //#endif
  104. verify.value = undefined;
  105. useStore.GetCodeImg({
  106. phone: phone.value,
  107. success: (res) => {
  108. proxy.$modal.msgSuccess("发送成功");
  109. },
  110. });
  111. }
  112. /**
  113. * @初始化
  114. */
  115. function init() {
  116. useStore.SetInterval("codeTime"); //调用倒计时定时器
  117. useStore.SET_LOGINMOBILELIST({
  118. loginTitle: "",
  119. loginBottomTitle: "",
  120. loginBg: "",
  121. loginLogo: "",
  122. tenantId: "",
  123. });
  124. //#ifdef H5
  125. if (window.location.host) {
  126. linkUrl.value = window.location.host;
  127. // linkUrl.value = "172.16.120.165:13200";
  128. // linkUrl.value = "localhost:81";
  129. useStore.GetMobileTenantConfig({ url: linkUrl.value });
  130. }
  131. //#endif
  132. //#ifdef APP-PLUS || MP-WEIXIN
  133. if (uni.getStorageSync("serveUrl")) {
  134. linkUrl.value = uni.getStorageSync("serveUrl");
  135. useStore.GetMobileTenantConfig({ url: linkUrl.value });
  136. } else {
  137. uni.setStorageSync("serveUrl", "manager.usky.cn");
  138. publicStore.setServeList("manager.usky.cn", "");
  139. linkUrl.value = uni.getStorageSync("serveUrl");
  140. useStore.GetMobileTenantConfig({ url: linkUrl.value });
  141. }
  142. //#endif
  143. }
  144. /** 点击提交按钮 */
  145. function submitRes() {
  146. //#ifdef APP-PLUS || MP-WEIXIN
  147. if (!uni.getStorageSync("serveUrl")) {
  148. proxy.$modal.msg("首次登录请先进行服务器配置");
  149. return;
  150. }
  151. if (!userChecked.value[0]) {
  152. proxy.$modal.msg("请在阅读并同意 用户协议和隐私协议后登录");
  153. return;
  154. }
  155. //#endif
  156. if (switchText.value == "账号密码登录") {
  157. if (!phone.value) {
  158. proxy.$modal.msg("请输入手机号");
  159. return;
  160. }
  161. 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)) {
  162. proxy.$modal.msg("请输入正确的手机号");
  163. return;
  164. }
  165. if (!verify.value) {
  166. proxy.$modal.msg("请输入验证码");
  167. return;
  168. }
  169. login({
  170. phone: phone.value,
  171. verify: verify.value,
  172. tenantId: useStore.$state.tenantId,
  173. });
  174. } else {
  175. if (!username.value) {
  176. proxy.$modal.msg("请输入账户");
  177. return;
  178. }
  179. if (!password.value) {
  180. proxy.$modal.msg("请输入密码");
  181. return;
  182. }
  183. login({
  184. username: username.value,
  185. password: password.value,
  186. tenantId: useStore.$state.tenantId,
  187. });
  188. }
  189. }
  190. /** 获取登录数据 */
  191. function login(data) {
  192. proxy.$modal.loading("登录中,请耐心等待...");
  193. useStore.Login(data).then(() => {
  194. /** 获取用户信息 */
  195. proxy.$modal.closeLoading();
  196. useStore.GetInfo().then((res) => {
  197. proxy.$tab.reLaunch("/pages/index");
  198. });
  199. });
  200. }
  201. // 用户协议
  202. function handleUserAgrement() {
  203. let site = config.appInfo.agreements[0];
  204. proxy.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
  205. }
  206. // 隐私协议
  207. function handlePrivacy() {
  208. let site = config.appInfo.agreements[1];
  209. proxy.$tab.navigateTo(`/pages/common/webview/index?title=${site.title}&url=${site.url}`);
  210. }
  211. onShow(() => {
  212. setTimeout(() => {
  213. init();
  214. }, 50);
  215. });
  216. onLoad((options) => {});
  217. </script>
  218. <style lang="scss" scoped>
  219. .login-container {
  220. position: fixed;
  221. top: 0;
  222. left: 0;
  223. right: 0;
  224. bottom: 0;
  225. display: flex;
  226. width: 100%;
  227. height: 100vh;
  228. background-color: $uni-bg-color;
  229. .bgImage {
  230. position: fixed;
  231. top: 0;
  232. left: 0;
  233. right: 0;
  234. z-index: 0;
  235. width: 100%;
  236. height: 100%;
  237. }
  238. .middle {
  239. position: relative;
  240. z-index: 1;
  241. width: 100%;
  242. padding: 0 30px;
  243. margin: auto;
  244. margin-top: 30%;
  245. &-top {
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. margin-bottom: 60px;
  250. .logo {
  251. height: 40px;
  252. width: auto;
  253. margin-right: 10px;
  254. }
  255. .title {
  256. font-size: 20px;
  257. color: #000;
  258. max-width: 50%;
  259. // white-space: nowrap;
  260. // overflow: hidden; //超出的文本隐藏
  261. // text-overflow: ellipsis; //溢出用省略号显示
  262. }
  263. }
  264. &-content {
  265. display: flex;
  266. position: relative;
  267. margin: 30px 0 30px 0;
  268. .title {
  269. margin: auto auto auto 0;
  270. color: #000;
  271. font-size: 18px;
  272. }
  273. .setting {
  274. color: #2a98ff;
  275. margin: auto 0;
  276. }
  277. .prompt {
  278. position: absolute;
  279. top: -35px;
  280. right: 0px;
  281. background-color: #2a98ff;
  282. text-align: center;
  283. line-height: 25px;
  284. display: inline-block;
  285. color: #fff;
  286. padding: 3px 5px;
  287. border-radius: 3px;
  288. &::after {
  289. content: "";
  290. position: absolute;
  291. border: 5px solid transparent;
  292. transform: rotate(90deg);
  293. right: 5px;
  294. bottom: -9px;
  295. border-left-color: #2a98ff;
  296. }
  297. }
  298. }
  299. // 登录页-服务器配置样式 开始
  300. &-input {
  301. :deep(.u-input) {
  302. height: 45px;
  303. border: 0 !important;
  304. border-radius: 8px;
  305. margin-bottom: 15px;
  306. padding: 5px 12px !important;
  307. background-color: #f5f6fa !important;
  308. }
  309. :deep(.input-placeholder) {
  310. color: #c0c4cc !important;
  311. }
  312. :deep(.uni-input-wrapper) {
  313. font-size: 16px;
  314. }
  315. :deep(.u-icon__icon) {
  316. font-size: 24px !important;
  317. line-height: 24px !important;
  318. color: gray !important;
  319. }
  320. :deep(.iconfont) {
  321. color: gray !important;
  322. }
  323. :deep(:-webkit-autofill) {
  324. caret-color: #000; // 设置光标颜色
  325. // -webkit-text-fill-color: gray !important;
  326. -webkit-box-shadow: 0 0 0px 1000px transparent inset !important;
  327. background-color: transparent;
  328. background-image: none;
  329. transition: background-color 50000s ease-in-out 0s; //背景色透明 生效时长 过渡效果 启用时延迟的时间
  330. }
  331. }
  332. &-switch {
  333. width: 100%;
  334. display: flex;
  335. margin-top: 20px;
  336. color: #96a6b5;
  337. &-loginMethod {
  338. display: block;
  339. }
  340. &-register {
  341. display: block;
  342. }
  343. }
  344. &-submit {
  345. height: 45px;
  346. line-height: 45px;
  347. border-radius: 24px;
  348. background: #2a98ff;
  349. color: #fff;
  350. border: 0px;
  351. }
  352. &-agreed {
  353. color: #96a6b5;
  354. margin-top: 30px;
  355. display: flex;
  356. justify-content: center;
  357. > uni-view {
  358. margin: auto 0;
  359. }
  360. > uni-text {
  361. margin: auto 0;
  362. }
  363. // animation: roundRule 0.5s linear infinite;
  364. }
  365. @keyframes roundRule {
  366. 0% {
  367. transform: translateX(0);
  368. }
  369. 50% {
  370. transform: translateX(-5px);
  371. }
  372. 100% {
  373. transform: translateX(0);
  374. }
  375. }
  376. }
  377. .bottom {
  378. position: fixed;
  379. width: 100%;
  380. bottom: 20px;
  381. .title {
  382. text-align: center;
  383. color: #96a6b5;
  384. font-size: 14px;
  385. }
  386. }
  387. }
  388. </style>