login.vue 15 KB

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