This commit is contained in:
80
docs/浅色深色.md
Normal file
80
docs/浅色深色.md
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
声明 color-scheme
|
||||||
|
有两种方式:
|
||||||
|
|
||||||
|
meta: 在head中声明<meta name="color-scheme" content="light dark">,声明当前页面支持 light 和 dark 两种模式,系统切换到深色模式时,浏览器默认样式也会切换到深色;
|
||||||
|
css:下面的 css 同样可以实现上面 meta 声明的效果
|
||||||
|
:root {
|
||||||
|
color-scheme: light dark;
|
||||||
|
}
|
||||||
|
注意:此声明并非为页面做自动适配,只影响浏览器默认样式
|
||||||
|
|
||||||
|
更多信息可查阅 W3C 文档 《CSS Color Adjustment Module Level 1》
|
||||||
|
|
||||||
|
通过 CSS 媒体查询
|
||||||
|
:root {
|
||||||
|
color-scheme: light dark;
|
||||||
|
background: white;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
background: black;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
颜色较多的情况,建议使用CSS变量对颜色值进行管理
|
||||||
|
|
||||||
|
:root {
|
||||||
|
color-scheme: light dark;
|
||||||
|
--nav-bg-color: #F7F7F7;
|
||||||
|
--content-bg-color: #FFFFFF;
|
||||||
|
--font-color: rgba(0,0,0,.9);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: dark) {
|
||||||
|
:root {
|
||||||
|
--nav-bg-color: #2F2F2F;
|
||||||
|
--content-bg-color: #2C2C2C;
|
||||||
|
--font-color: rgba(255, 255, 255, .8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:root {
|
||||||
|
color: var(--font-color)
|
||||||
|
}
|
||||||
|
|
||||||
|
.header {
|
||||||
|
background-color: var(--nav-bg-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
background-color: var(--content-bg-color);
|
||||||
|
}
|
||||||
|
图片适配
|
||||||
|
利用picture+source标签,设置不同模式下的图片 url。
|
||||||
|
|
||||||
|
<picture>
|
||||||
|
<!-- 深色模式下的图片 -->
|
||||||
|
<source srcset="dark.jpg" media="(prefers-color-scheme: dark)" />
|
||||||
|
<!-- 默认模式下的图片 -->
|
||||||
|
<img src="light.jpg"/>
|
||||||
|
</picture>
|
||||||
|
JavaScript中判断当前模式&监听模式变化
|
||||||
|
利用的是matchMedia方法,具体用法参考以下例子:
|
||||||
|
|
||||||
|
|
||||||
|
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)')
|
||||||
|
|
||||||
|
function darkModeHandler() {
|
||||||
|
if (mediaQuery.matches) {
|
||||||
|
console.log('现在是深色模式')
|
||||||
|
} else {
|
||||||
|
console.log('现在是浅色模式')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断当前模式
|
||||||
|
darkModeHandler()
|
||||||
|
// 监听模式变化
|
||||||
|
mediaQuery.addListener(darkModeHandler)
|
||||||
@@ -1,14 +1,50 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="container">
|
<view class="login-page">
|
||||||
|
<view class="content">
|
||||||
<view class="card">
|
<view class="card">
|
||||||
<view class="title-login">
|
<view class="card-title">用户登录</view>
|
||||||
登录
|
|
||||||
|
<view class="form-item">
|
||||||
|
<view class="label">设备标识</view>
|
||||||
|
<view class="input-wrap" :class="{ focus: inputFocus }">
|
||||||
|
<input
|
||||||
|
v-model="identifier"
|
||||||
|
class="input"
|
||||||
|
placeholder="请输入SN/IMEI/虚拟号/ICCID/MSISDN"
|
||||||
|
placeholder-class="placeholder"
|
||||||
|
@focus="inputFocus = true"
|
||||||
|
@blur="inputFocus = false"
|
||||||
|
@input="showError = false"
|
||||||
|
/>
|
||||||
|
<view v-if="identifier" class="clear" @tap="identifier = ''">
|
||||||
|
<text>×</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="input">
|
|
||||||
<up-input class="mt-30" v-model="identifier" placeholder="请输入SN/IMEI/虚拟号/ICCID/MSISDN"></up-input>
|
|
||||||
</view>
|
</view>
|
||||||
<view class="button">
|
<text v-if="showError" class="error">请输入设备标识</text>
|
||||||
<up-button class="mt-30 btn-apple btn-primary" type="primary" :loading="loading" @click="login">立即登录</up-button>
|
</view>
|
||||||
|
|
||||||
|
<view class="form-item">
|
||||||
|
<button
|
||||||
|
class="btn-login"
|
||||||
|
:class="{ disabled: !identifier || loading }"
|
||||||
|
:disabled="!identifier || loading"
|
||||||
|
@tap="handleLogin"
|
||||||
|
>
|
||||||
|
<view v-if="loading" class="loading">
|
||||||
|
<view class="dot"/>
|
||||||
|
<view class="dot"/>
|
||||||
|
<view class="dot"/>
|
||||||
|
</view>
|
||||||
|
<text v-else>登录</text>
|
||||||
|
</button>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
<view class="agreement">
|
||||||
|
<text class="agree-text">登录即表示同意</text>
|
||||||
|
<text class="link">《用户协议》</text>
|
||||||
|
<text class="agree-text">和</text>
|
||||||
|
<text class="link">《隐私政策》</text>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -18,14 +54,15 @@
|
|||||||
import { ref, onMounted } from 'vue';
|
import { ref, onMounted } from 'vue';
|
||||||
import { authApi } from '@/api/index.js';
|
import { authApi } from '@/api/index.js';
|
||||||
import { useUserStore } from '@/store/index.js';
|
import { useUserStore } from '@/store/index.js';
|
||||||
import { APP_ID } from '@/utils/env.js';
|
import { APP_ID, USE_WECHAT_AUTH } from '@/utils/env.js';
|
||||||
|
|
||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
|
|
||||||
const identifier = ref('');
|
const identifier = ref('');
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
const agreed = ref(true);
|
||||||
const isWechat = /micromessenger/i.test(navigator.userAgent);
|
const inputFocus = ref(false);
|
||||||
|
const showError = ref(false);
|
||||||
|
|
||||||
const getCode = () => {
|
const getCode = () => {
|
||||||
const params = new URLSearchParams(window.location.search);
|
const params = new URLSearchParams(window.location.search);
|
||||||
@@ -42,23 +79,28 @@
|
|||||||
window.location.href = url;
|
window.location.href = url;
|
||||||
};
|
};
|
||||||
|
|
||||||
const login = async () => {
|
const handleLogin = () => {
|
||||||
if (!identifier.value) {
|
if (!identifier.value) {
|
||||||
uni.showToast({ title: '请输入SN/IMEI/虚拟号/ICCID/MSISDN', icon: 'none' });
|
showError.value = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
doLogin();
|
||||||
|
};
|
||||||
|
|
||||||
|
const doLogin = async () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
try {
|
try {
|
||||||
const verifyData = await authApi.verifyAsset(identifier.value);
|
const verifyData = await authApi.verifyAsset(identifier.value);
|
||||||
userStore.setAssetToken(verifyData.asset_token);
|
userStore.setAssetToken(verifyData.asset_token);
|
||||||
userStore.setIdentifier(identifier.value);
|
userStore.setIdentifier(identifier.value);
|
||||||
|
|
||||||
// if (!isWechat) {
|
if (!USE_WECHAT_AUTH) {
|
||||||
// uni.showToast({ title: '请在微信中打开', icon: 'none' });
|
const loginData = await authApi.wechatLogin(verifyData.asset_token, 'mock_code');
|
||||||
// loading.value = false;
|
userStore.setToken(loginData.token);
|
||||||
// return;
|
uni.setStorageSync('identifier', userStore.state.identifier);
|
||||||
// }
|
uni.redirectTo({ url: '/pages/index/index' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
redirectToWxAuth(verifyData.asset_token);
|
redirectToWxAuth(verifyData.asset_token);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -68,6 +110,8 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleWechatCallback = async () => {
|
const handleWechatCallback = async () => {
|
||||||
|
if (!USE_WECHAT_AUTH) return;
|
||||||
|
|
||||||
const code = getCode();
|
const code = getCode();
|
||||||
const assetToken = userStore.state.assetToken;
|
const assetToken = userStore.state.assetToken;
|
||||||
|
|
||||||
@@ -94,23 +138,146 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.container {
|
.login-page {
|
||||||
padding-top: 30vh;
|
min-height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
background: #FFFFFF;
|
||||||
|
}
|
||||||
|
|
||||||
.title-login {
|
.card {
|
||||||
color: var(--text-primary);
|
background: #FFFFFF;
|
||||||
font-size: 24px;
|
border-radius: 24rpx;
|
||||||
text-align: center;
|
padding: 48rpx;
|
||||||
margin: 20px 0;
|
box-shadow: 0 8rpx 40rpx rgba(0, 0, 0, 0.08);
|
||||||
font-weight: bold;
|
}
|
||||||
|
|
||||||
|
.card-title {
|
||||||
|
font-size: 40rpx;
|
||||||
|
font-weight: 600;
|
||||||
|
color: #1A1A1A;
|
||||||
|
margin-bottom: 48rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-item {
|
||||||
|
margin-bottom: 32rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
font-size: 26rpx;
|
||||||
|
color: #6B7280;
|
||||||
|
margin-bottom: 16rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-wrap {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
background: #F9FAFB;
|
||||||
|
border: 2rpx solid #E5E7EB;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
padding: 0 24rpx;
|
||||||
|
height: 96rpx;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.input-wrap.focus {
|
||||||
|
border-color: #2563EB;
|
||||||
|
background: #FFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
.input {
|
.input {
|
||||||
margin: 70rpx 0 50rpx 0;
|
flex: 1;
|
||||||
|
font-size: 30rpx;
|
||||||
|
color: #1A1A1A;
|
||||||
|
background: transparent;
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.placeholder {
|
||||||
margin-bottom: 40rpx;
|
color: #9CA3AF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.clear {
|
||||||
|
width: 40rpx;
|
||||||
|
height: 40rpx;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
color: #9CA3AF;
|
||||||
|
font-size: 36rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #EF4444;
|
||||||
|
margin-top: 12rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-login {
|
||||||
|
width: 100%;
|
||||||
|
height: 96rpx;
|
||||||
|
background: #2563EB;
|
||||||
|
border: none;
|
||||||
|
border-radius: 16rpx;
|
||||||
|
font-size: 32rpx;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #FFFFFF;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
transition: all 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-login.disabled {
|
||||||
|
background: #E5E7EB;
|
||||||
|
color: #9CA3AF;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-login:active:not(.disabled) {
|
||||||
|
background: #1D4ED8;
|
||||||
|
}
|
||||||
|
|
||||||
|
.loading {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dot {
|
||||||
|
width: 8rpx;
|
||||||
|
height: 8rpx;
|
||||||
|
background: #9CA3AF;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: load 1.4s infinite ease-in-out both;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dot:nth-child(1) { animation-delay: -0.32s; }
|
||||||
|
.dot:nth-child(2) { animation-delay: -0.16s; }
|
||||||
|
|
||||||
|
@keyframes load {
|
||||||
|
0%, 80%, 100% { transform: scale(0); }
|
||||||
|
40% { transform: scale(1); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.agreement {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: nowrap;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
gap: 8rpx;
|
||||||
|
margin-top: 40rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
.agree-text {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #9CA3AF;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link {
|
||||||
|
font-size: 24rpx;
|
||||||
|
color: #2563EB;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
2
uni.scss
2
uni.scss
@@ -74,3 +74,5 @@ $uni-color-subtitle: #555555; // 二级标题颜色
|
|||||||
$uni-font-size-subtitle:26px;
|
$uni-font-size-subtitle:26px;
|
||||||
$uni-color-paragraph: #3F536E; // 文章段落颜色
|
$uni-color-paragraph: #3F536E; // 文章段落颜色
|
||||||
$uni-font-size-paragraph:15px;
|
$uni-font-size-paragraph:15px;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
export const BASE_URL = 'https://cmp-api.boss160.cn';
|
export const BASE_URL = 'https://cmp-api.boss160.cn';
|
||||||
|
|
||||||
export const APP_TYPE = 'miniapp';
|
export const APP_TYPE = 'official_account';
|
||||||
|
|
||||||
export const APP_ID = 'wxea8c599fe100ce8a';
|
export const APP_ID = 'wx404dc822ce15c5f0';
|
||||||
|
|
||||||
|
export const USE_WECHAT_AUTH = true;
|
||||||
Reference in New Issue
Block a user