login.vue 12 KB

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