杂务:整理文档并收口 YumiNail 修复
This commit is contained in:
@@ -192,7 +192,11 @@ async function refreshToken() {
|
||||
}
|
||||
|
||||
async function handleUnauthorized(options) {
|
||||
if (options._retry || isWhitelistedPath(options.url)) {
|
||||
if (isWhitelistedPath(options.url)) {
|
||||
throw normalizeError('\u8bf7\u6c42\u9700\u8981\u767b\u5f55\uff0c\u4f46\u5f53\u524d\u9875\u9762\u5141\u8bb8\u533f\u540d\u67e5\u770b', 401)
|
||||
}
|
||||
|
||||
if (options._retry) {
|
||||
auth.clearSession()
|
||||
const app = getApp()
|
||||
if (app && typeof app.clearUserSession === 'function') {
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
const HEX_COLOR_PATTERN = /^#[0-9a-fA-F]{6}$/
|
||||
|
||||
function normalizeHexColor(value) {
|
||||
if (!value || typeof value !== 'string') {
|
||||
return ''
|
||||
}
|
||||
const normalized = value.trim()
|
||||
return HEX_COLOR_PATTERN.test(normalized) ? normalized.toUpperCase() : ''
|
||||
}
|
||||
|
||||
function hexToRgb(color) {
|
||||
const value = color.replace('#', '')
|
||||
return {
|
||||
r: parseInt(value.slice(0, 2), 16),
|
||||
g: parseInt(value.slice(2, 4), 16),
|
||||
b: parseInt(value.slice(4, 6), 16)
|
||||
}
|
||||
}
|
||||
|
||||
function toHex(value) {
|
||||
return Math.min(255, Math.max(0, value)).toString(16).padStart(2, '0').toUpperCase()
|
||||
}
|
||||
|
||||
function rgbToHex(rgb) {
|
||||
return `#${toHex(rgb.r)}${toHex(rgb.g)}${toHex(rgb.b)}`
|
||||
}
|
||||
|
||||
function mixColor(foreground, background, backgroundWeight) {
|
||||
const fg = hexToRgb(foreground)
|
||||
const bg = hexToRgb(background)
|
||||
const weight = Math.min(1, Math.max(0, backgroundWeight))
|
||||
return rgbToHex({
|
||||
r: Math.round(fg.r * (1 - weight) + bg.r * weight),
|
||||
g: Math.round(fg.g * (1 - weight) + bg.g * weight),
|
||||
b: Math.round(fg.b * (1 - weight) + bg.b * weight)
|
||||
})
|
||||
}
|
||||
|
||||
function buildStyleVars(theme) {
|
||||
const styleVars = [
|
||||
`--theme-primary: ${theme.primaryColor};`,
|
||||
`--theme-secondary: ${theme.secondaryColor};`,
|
||||
`--theme-accent: ${theme.accentColor};`,
|
||||
`--theme-page-bg: ${theme.pageBgColor};`,
|
||||
`--theme-card-bg: ${theme.cardBgColor};`,
|
||||
`--theme-border: ${theme.borderColor};`,
|
||||
`--theme-primary-soft: ${theme.primarySoftColor};`,
|
||||
`--theme-gradient: ${theme.gradient};`,
|
||||
`--theme-gradient-soft: ${theme.softGradient};`
|
||||
]
|
||||
if (theme.backgroundImageUrl) {
|
||||
styleVars.push(
|
||||
`background-image: url("${theme.backgroundImageUrl}");`,
|
||||
'background-size: cover;',
|
||||
'background-position: center top;'
|
||||
)
|
||||
}
|
||||
return styleVars.join(' ')
|
||||
}
|
||||
|
||||
function resolveShopTheme(source) {
|
||||
const themeSource = source || {}
|
||||
const normalizedPrimaryColor = normalizeHexColor(themeSource.themePrimaryColor)
|
||||
const primaryColor = normalizedPrimaryColor || DEFAULT_SHOP_THEME.primaryColor
|
||||
const secondaryColor = normalizeHexColor(themeSource.themeSecondaryColor)
|
||||
|| (normalizedPrimaryColor ? mixColor(primaryColor, '#FFFFFF', 0.68) : DEFAULT_SHOP_THEME.secondaryColor)
|
||||
const accentColor = normalizeHexColor(themeSource.themeAccentColor)
|
||||
|| (normalizedPrimaryColor ? mixColor(primaryColor, '#7A3F56', 0.38) : DEFAULT_SHOP_THEME.accentColor)
|
||||
const pageBgColor = normalizeHexColor(themeSource.themePageBgColor) || DEFAULT_SHOP_THEME.pageBgColor
|
||||
const cardBgColor = normalizeHexColor(themeSource.themeCardBgColor) || DEFAULT_SHOP_THEME.cardBgColor
|
||||
const borderColor = mixColor(primaryColor, cardBgColor, 0.82)
|
||||
const primarySoftColor = mixColor(primaryColor, cardBgColor, 0.88)
|
||||
const gradient = `linear-gradient(135deg, ${primaryColor} 0%, ${secondaryColor} 100%)`
|
||||
const softGradient = `linear-gradient(145deg, ${cardBgColor} 0%, ${mixColor(secondaryColor, pageBgColor, 0.55)} 58%, ${mixColor(primaryColor, pageBgColor, 0.82)} 100%)`
|
||||
const backgroundImageFileId = themeSource.themeBackgroundImageFileId
|
||||
? String(themeSource.themeBackgroundImageFileId).trim()
|
||||
: ''
|
||||
const backgroundImageUrl = themeSource.themeBackgroundImageUrl
|
||||
? String(themeSource.themeBackgroundImageUrl).trim()
|
||||
: ''
|
||||
const theme = {
|
||||
primaryColor,
|
||||
secondaryColor,
|
||||
accentColor,
|
||||
pageBgColor,
|
||||
cardBgColor,
|
||||
borderColor,
|
||||
primarySoftColor,
|
||||
gradient,
|
||||
softGradient,
|
||||
backgroundImageFileId,
|
||||
backgroundImageUrl
|
||||
}
|
||||
theme.styleVars = buildStyleVars(theme)
|
||||
return theme
|
||||
}
|
||||
|
||||
const DEFAULT_SHOP_THEME = {
|
||||
primaryColor: '#C6597D',
|
||||
secondaryColor: '#E9B7C7',
|
||||
accentColor: '#9F4967',
|
||||
pageBgColor: '#FFF7F9',
|
||||
cardBgColor: '#FFFFFF',
|
||||
borderColor: '#EFD8E0',
|
||||
primarySoftColor: '#FBF1F4',
|
||||
gradient: 'linear-gradient(135deg, #C6597D 0%, #E9B7C7 100%)',
|
||||
softGradient: 'linear-gradient(145deg, #FFFFFF 0%, #FFF1F5 58%, #FFE8EF 100%)',
|
||||
backgroundImageFileId: '',
|
||||
backgroundImageUrl: ''
|
||||
}
|
||||
|
||||
DEFAULT_SHOP_THEME.styleVars = buildStyleVars(DEFAULT_SHOP_THEME)
|
||||
|
||||
function pageThemeData(theme, backgroundImageUrl) {
|
||||
const resolved = theme || DEFAULT_SHOP_THEME
|
||||
const themeData = backgroundImageUrl
|
||||
? {
|
||||
...resolved,
|
||||
backgroundImageUrl: String(backgroundImageUrl).trim()
|
||||
}
|
||||
: resolved
|
||||
if (backgroundImageUrl) {
|
||||
themeData.styleVars = buildStyleVars(themeData)
|
||||
}
|
||||
return {
|
||||
theme: themeData,
|
||||
themeVars: themeData.styleVars,
|
||||
navThemeColor: themeData.primaryColor,
|
||||
navThemeBackground: themeData.pageBgColor
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
DEFAULT_SHOP_THEME,
|
||||
resolveShopTheme,
|
||||
pageThemeData
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
const assert = require('assert')
|
||||
const theme = require('./theme')
|
||||
|
||||
const customized = theme.resolveShopTheme({
|
||||
themePrimaryColor: '#8b4f65',
|
||||
themeSecondaryColor: '#f2c9d4',
|
||||
themeAccentColor: '#b86f84',
|
||||
themePageBgColor: '#fff8fa',
|
||||
themeCardBgColor: '#ffffff',
|
||||
themeBackgroundImageFileId: 'bg-file'
|
||||
})
|
||||
|
||||
assert.strictEqual(customized.primaryColor, '#8B4F65')
|
||||
assert.strictEqual(customized.secondaryColor, '#F2C9D4')
|
||||
assert.strictEqual(customized.accentColor, '#B86F84')
|
||||
assert.strictEqual(customized.pageBgColor, '#FFF8FA')
|
||||
assert.strictEqual(customized.cardBgColor, '#FFFFFF')
|
||||
assert.strictEqual(customized.backgroundImageFileId, 'bg-file')
|
||||
assert.ok(customized.styleVars.includes('--theme-primary: #8B4F65;'))
|
||||
assert.ok(customized.styleVars.includes('--theme-gradient: linear-gradient(135deg, #8B4F65 0%, #F2C9D4 100%);'))
|
||||
|
||||
const themedPageData = theme.pageThemeData(customized, 'https://static.example.test/bg.jpg')
|
||||
assert.ok(themedPageData.themeVars.includes('background-image: url("https://static.example.test/bg.jpg");'))
|
||||
assert.strictEqual(themedPageData.theme.backgroundImageUrl, 'https://static.example.test/bg.jpg')
|
||||
|
||||
const fallback = theme.resolveShopTheme({
|
||||
themePrimaryColor: '#fff',
|
||||
themeSecondaryColor: 'blue'
|
||||
})
|
||||
|
||||
assert.strictEqual(fallback.primaryColor, theme.DEFAULT_SHOP_THEME.primaryColor)
|
||||
assert.strictEqual(fallback.secondaryColor, theme.DEFAULT_SHOP_THEME.secondaryColor)
|
||||
assert.ok(fallback.styleVars.includes('--theme-page-bg:'))
|
||||
Reference in New Issue
Block a user