login.vue 15 KB

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