login.vue 11 KB

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