This commit is contained in:
2025-11-14 11:39:33 +08:00
parent 6e5d892992
commit 1ba633ba45
7143 changed files with 922330 additions and 0 deletions

39
node_modules/@dcloudio/uni-h5/src/shared/callback.js generated vendored Normal file
View File

@@ -0,0 +1,39 @@
let id = 0
const callbacks = {}
function warp (fn) {
return function (options = {}) {
const callbackId = String(id++)
callbacks[callbackId] = {
success: options.success,
fail: options.fail,
complete: options.complete
}
const data = Object.assign({}, options)
// TODO 下版重构 nvue h5 callback
// delete data.success
// delete data.fail
// delete data.complete
const res = fn.bind(this)(data, callbackId)
if (res) {
invoke(callbackId, res)
}
}
}
function invoke (callbackId, res) {
const callback = callbacks[callbackId] || {}
delete callbacks[callbackId]
const errMsg = res.errMsg || ''
if (new RegExp('\\:\\s*fail').test(errMsg)) {
callback.fail && callback.fail(res)
} else {
callback.success && callback.success(res)
}
callback.complete && callback.complete(res)
}
export const callback = {
warp,
invoke
}

50
node_modules/@dcloudio/uni-h5/src/shared/color.js generated vendored Normal file
View File

@@ -0,0 +1,50 @@
/**
* 从 16 进制的色值解析成 rgba 格式的色值
* @param { string } hex, #000、#000A、#000000、#000000AA参数只能是这四种格式
* @returns {
r: number;
g: number;
b: number;
a: number;
}
*/
export function hexToRgba (hex) {
// 异常情况
if (!hex) {
return {
r: 0,
g: 0,
b: 0,
a: 0
}
}
// 去掉 #
let tmpHex = hex.slice(1)
const tmpHexLen = tmpHex.length
// 处理 16 进制色值位数异常的情况
if (![3, 4, 6, 8].includes(tmpHexLen)) {
return {
r: 0,
g: 0,
b: 0,
a: 0
}
}
// 格式化 tmpHex使其变成 rrggbb 或 rrggbbaa
if (tmpHexLen === 3 || tmpHexLen === 4) {
// rgb => rrggbb || rgba => rrggbbaa
tmpHex = tmpHex.replace(/(\w{1})/g, '$1$1')
}
// rgba
const [sr, sg, sb, sa] = tmpHex.match(/(\w{2})/g)
// rgb
const r = parseInt(sr, 16); const g = parseInt(sg, 16); const b = parseInt(sb, 16)
if (!sa) {
return { r, g, b, a: 1 }
}
return {
r, g, b, a: (`0x100${sa}` - 0x10000) / 255
}
}

11
node_modules/@dcloudio/uni-h5/src/shared/env.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
export let supportsPassive = false
try {
const opts = {}
Object.defineProperty(opts, 'passive', ({
get () {
/* istanbul ignore next */
supportsPassive = true
}
})) // https://github.com/facebook/flow/issues/285
window.addEventListener('test-passive', null, opts)
} catch (e) {}

7
node_modules/@dcloudio/uni-h5/src/shared/index.js generated vendored Normal file
View File

@@ -0,0 +1,7 @@
export * from './env'
export * from './util'
export * from './color'
export * from './query'
export * from './platform'
export * from './callback'
export * from './theme'

22
node_modules/@dcloudio/uni-h5/src/shared/path.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
export function parsePath (path) {
let hash = ''
let query = ''
const hashIndex = path.indexOf('#')
if (hashIndex >= 0) {
hash = path.slice(hashIndex)
path = path.slice(0, hashIndex)
}
const queryIndex = path.indexOf('?')
if (queryIndex >= 0) {
query = path.slice(queryIndex + 1)
path = path.slice(0, queryIndex)
}
return {
path,
query,
hash
}
}

9
node_modules/@dcloudio/uni-h5/src/shared/platform.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
export function plusReady (callback) {
if (typeof callback !== 'function') {
return
}
if (window.plus) {
return callback()
}
document.addEventListener('plusready', callback)
}

84
node_modules/@dcloudio/uni-h5/src/shared/query.js generated vendored Normal file
View File

@@ -0,0 +1,84 @@
const encodeReserveRE = /[!'()*]/g
const encodeReserveReplacer = c => '%' + c.charCodeAt(0).toString(16)
const commaRE = /%2C/g
// fixed encodeURIComponent which is more conformant to RFC3986:
// - escapes [!'()*]
// - preserve commas
const encode = str => encodeURIComponent(str)
.replace(encodeReserveRE, encodeReserveReplacer)
.replace(commaRE, ',')
const decode = decodeURIComponent
export function parseQuery (query) {
const res = {}
query = query.trim().replace(/^(\?|#|&)/, '')
if (!query) {
return res
}
query.split('&').forEach(param => {
const parts = param.replace(/\+/g, ' ').split('=')
const key = decode(parts.shift())
const val = parts.length > 0
? decode(parts.join('='))
: null
if (res[key] === undefined) {
res[key] = val
} else if (Array.isArray(res[key])) {
res[key].push(val)
} else {
res[key] = [res[key], val]
}
})
return res
}
export function stringifyQuery (obj, encodeStr = encode) {
const res = obj ? Object.keys(obj).map(key => {
const val = obj[key]
if (val === undefined) {
return ''
}
if (val === null) {
return encodeStr(key)
}
if (Array.isArray(val)) {
const result = []
val.forEach(val2 => {
if (val2 === undefined) {
return
}
if (val2 === null) {
result.push(encodeStr(key))
} else {
result.push(encodeStr(key) + '=' + encodeStr(val2))
}
})
return result.join('&')
}
return encodeStr(key) + '=' + encodeStr(val)
}).filter(x => x.length > 0).join('&') : null
return res ? `?${res}` : ''
}
export function decodedQuery (query = {}) {
const decodedQuery = {}
Object.keys(query).forEach(name => {
try {
decodedQuery[name] = decode(query[name])
} catch (e) {
decodedQuery[name] = query[name]
}
})
return decodedQuery
}

65
node_modules/@dcloudio/uni-h5/src/shared/theme.js generated vendored Normal file
View File

@@ -0,0 +1,65 @@
import { isPlainObject, isString, isArray } from './util'
const borderStyles = {
black: 'rgba(0,0,0,0.4)',
white: 'rgba(255,255,255,0.4)'
}
export function normalizeTabBarStyles (borderStyle) {
if (borderStyle && borderStyle in borderStyles) {
return borderStyles[borderStyle]
}
return borderStyle
}
export function normalizeTitleColor (titleColor) {
return titleColor === 'black' ? '#000000' : '#ffffff'
}
function resolveStringStyleItem (modeStyle, styleItem, key) {
if (isString(styleItem) && styleItem.startsWith('@')) {
const _key = styleItem.replace('@', '')
let _styleItem = modeStyle[_key] || styleItem
switch (key) {
case 'titleColor':
_styleItem = normalizeTitleColor(_styleItem)
break
case 'borderStyle':
_styleItem = normalizeTabBarStyles(_styleItem)
break
default:
break
}
return _styleItem
}
return styleItem
}
export function normalizeStyles (pageStyle, themeConfig = {}, mode = 'light') {
const modeStyle = themeConfig[mode]
const styles = {}
if (typeof modeStyle === 'undefined' || !pageStyle) return pageStyle
Object.keys(pageStyle).forEach(key => {
const styleItem = pageStyle[key] // Object Array String
const parseStyleItem = () => {
if (isPlainObject(styleItem)) { return normalizeStyles(styleItem, themeConfig, mode) }
if (isArray(styleItem)) {
return styleItem.map(item => {
if (isPlainObject(item)) { return normalizeStyles(item, themeConfig, mode) }
return resolveStringStyleItem(modeStyle, item)
})
}
return resolveStringStyleItem(modeStyle, styleItem, key)
}
styles[key] = parseStyleItem()
})
return styles
}

View File

@@ -0,0 +1,77 @@
let realAtob
const b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
const b64re = /^(?:[A-Za-z\d+/]{4})*?(?:[A-Za-z\d+/]{2}(?:==)?|[A-Za-z\d+/]{3}=?)?$/
if (typeof atob !== 'function') {
realAtob = function (str) {
str = String(str).replace(/[\t\n\f\r ]+/g, '')
if (!b64re.test(str)) { throw new Error("Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.") }
// Adding the padding if missing, for semplicity
str += '=='.slice(2 - (str.length & 3))
var bitmap; var result = ''; var r1; var r2; var i = 0
for (; i < str.length;) {
bitmap = b64.indexOf(str.charAt(i++)) << 18 | b64.indexOf(str.charAt(i++)) << 12 |
(r1 = b64.indexOf(str.charAt(i++))) << 6 | (r2 = b64.indexOf(str.charAt(i++)))
result += r1 === 64 ? String.fromCharCode(bitmap >> 16 & 255)
: r2 === 64 ? String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255)
: String.fromCharCode(bitmap >> 16 & 255, bitmap >> 8 & 255, bitmap & 255)
}
return result
}
} else {
// 注意atob只能在全局对象上调用例如`const Base64 = {atob};Base64.atob('xxxx')`是错误的用法
realAtob = atob
}
function b64DecodeUnicode (str) {
return decodeURIComponent(realAtob(str).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
}).join(''))
}
function getCurrentUserInfo () {
const token = (__PLATFORM__ === 'h5' || __PLATFORM__ === 'app-plus' ? uni : __GLOBAL__).getStorageSync('uni_id_token') || ''
const tokenArr = token.split('.')
if (!token || tokenArr.length !== 3) {
return {
uid: null,
role: [],
permission: [],
tokenExpired: 0
}
}
let userInfo
try {
userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1]))
} catch (error) {
throw new Error('获取当前用户信息出错,详细错误信息为:' + error.message)
}
userInfo.tokenExpired = userInfo.exp * 1000
delete userInfo.exp
delete userInfo.iat
return userInfo
}
export function uniIdMixin (Vue) {
Vue.prototype.uniIDHasRole = function (roleId) {
const {
role
} = getCurrentUserInfo()
return role.indexOf(roleId) > -1
}
Vue.prototype.uniIDHasPermission = function (permissionId) {
const {
permission
} = getCurrentUserInfo()
return this.uniIDHasRole('admin') || permission.indexOf(permissionId) > -1
}
Vue.prototype.uniIDTokenValid = function () {
const {
tokenExpired
} = getCurrentUserInfo()
return tokenExpired > Date.now()
}
}

223
node_modules/@dcloudio/uni-h5/src/shared/util.js generated vendored Normal file
View File

@@ -0,0 +1,223 @@
const _toString = Object.prototype.toString
const hasOwnProperty = Object.prototype.hasOwnProperty
const _completeValue = value => {
return value > 9 ? value : ('0' + value)
}
export const isArray = Array.isArray
export const extend = Object.assign
export function isFn (fn) {
return typeof fn === 'function'
}
export function isStr (str) {
return typeof str === 'string'
}
export const isString = isStr
export function isObject (obj) {
return obj !== null && typeof obj === 'object'
}
export function isPlainObject (obj) {
return _toString.call(obj) === '[object Object]'
}
export function hasOwn (obj, key) {
return hasOwnProperty.call(obj, key)
}
export function noop () {}
export function toRawType (val) {
return _toString.call(val).slice(8, -1)
}
/**
* Create a cached version of a pure function.
*/
export function cached (fn) {
const cache = Object.create(null)
return function cachedFn (str) {
const hit = cache[str]
return hit || (cache[str] = fn(str))
}
}
export function once (fn, ctx = null) {
let res
return (...args) => {
if (fn) {
res = fn.apply(ctx, args)
fn = null
}
return res
}
}
/**
* Camelize a hyphen-delimited string.
*/
const camelizeRE = /-(\w)/g
export const camelize = cached((str) => {
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '')
})
/**
* Capitalize a string.
*/
export const capitalize = cached((str) => {
return str.charAt(0).toUpperCase() + str.slice(1)
})
export function setProperties (item, props, propsData) {
props.forEach(function (name) {
if (hasOwn(propsData, name)) {
item[name] = propsData[name]
}
})
}
export function getLen (str = '') {
/* eslint-disable no-control-regex */
return ('' + str).replace(/[^\x00-\xff]/g, '**').length
}
export function formatDateTime ({
date = new Date(),
mode = 'date'
}) {
if (mode === 'time') {
return _completeValue(date.getHours()) + ':' + _completeValue(date.getMinutes())
} else {
return date.getFullYear() + '-' + _completeValue(date.getMonth() + 1) + '-' + _completeValue(date.getDate())
}
}
export function updateElementStyle (element, styles) {
for (const attrName in styles) {
element.style[attrName] = styles[attrName]
}
}
export function guid () {
return Math.floor(4294967296 * (1 + Math.random())).toString(16).slice(1)
}
export function debounce (fn, delay) {
let timeout
const newFn = function () {
clearTimeout(timeout)
const timerFn = () => fn.apply(this, arguments)
timeout = setTimeout(timerFn, delay)
}
newFn.cancel = function () {
clearTimeout(timeout)
}
return newFn
}
export function throttle (fn, wait) {
let last = 0
let timeout
let waitCallback
const newFn = function (...arg) {
const now = Date.now()
clearTimeout(timeout)
waitCallback = () => {
waitCallback = null
last = now
fn.apply(this, arg)
}
if (now - last < wait) {
timeout = setTimeout(waitCallback, wait - (now - last))
return
}
waitCallback()
}
newFn.cancel = function () {
clearTimeout(timeout)
waitCallback = null
}
newFn.flush = function () {
clearTimeout(timeout)
waitCallback && waitCallback()
}
return newFn
}
export function kebabCase (string) {
return string.replace(/[A-Z]/g, str => '-' + str.toLowerCase())
}
/**
* Check if two values are loosely equal - that is,
* if they are plain objects, do they have the same shape?
*/
export function looseEqual (a, b) {
if (a === b) return true
const isObjectA = isObject(a)
const isObjectB = isObject(b)
if (isObjectA && isObjectB) {
try {
const isArrayA = Array.isArray(a)
const isArrayB = Array.isArray(b)
if (isArrayA && isArrayB) {
return a.length === b.length && a.every((e, i) => {
return looseEqual(e, b[i])
})
} else if (a instanceof Date && b instanceof Date) {
return a.getTime() === b.getTime()
} else if (!isArrayA && !isArrayB) {
const keysA = Object.keys(a)
const keysB = Object.keys(b)
return keysA.length === keysB.length && keysA.every(key => {
return looseEqual(a[key], b[key])
})
} else {
/* istanbul ignore next */
return false
}
} catch (e) {
/* istanbul ignore next */
return false
}
} else if (!isObjectA && !isObjectB) {
return String(a) === String(b)
} else {
return false
}
}
export function deepClone (vnodes, createElement) {
function cloneVNode (vnode) {
var clonedChildren = vnode.children && vnode.children.map(cloneVNode)
var cloned = createElement(vnode.tag, vnode.data, clonedChildren)
cloned.text = vnode.text
cloned.isComment = vnode.isComment
cloned.componentOptions = vnode.componentOptions
cloned.elm = vnode.elm
cloned.context = vnode.context
cloned.ns = vnode.ns
cloned.isStatic = vnode.isStatic
cloned.key = vnode.key
return cloned
}
return vnodes.map(cloneVNode)
}
export * from './uni-id-mixin'
export function sortObject (obj) {
const sortObj = {}
if (isPlainObject(obj)) {
Object.keys(obj).sort().forEach(key => {
sortObj[key] = obj[key]
})
}
return !Object.keys(sortObj) ? obj : sortObj
}