提交模型设计代码
This commit is contained in:
15
src/utils/enum.js
Normal file
15
src/utils/enum.js
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Copyright [2022] [https://www.xiaonuo.vip]
|
||||
* Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Snowy源码头部的版权声明。
|
||||
* 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
|
||||
* 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
||||
* 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
||||
*/
|
||||
export const ThemeModeEnum = {
|
||||
LIGHT: 'light',
|
||||
DARK: 'dark',
|
||||
REAL_DARK: 'realDark'
|
||||
}
|
||||
39
src/utils/objects.js
Normal file
39
src/utils/objects.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Copyright [2022] [https://www.xiaonuo.vip]
|
||||
* Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Snowy源码头部的版权声明。
|
||||
* 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
|
||||
* 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
||||
* 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
||||
*/
|
||||
import pinyin from 'js-pinyin'
|
||||
|
||||
// 中文转拼音 传入仅首字母
|
||||
Object.defineProperty(String.prototype, 'toPinyin', {
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
value: function (first) {
|
||||
let str = this
|
||||
if (first) {
|
||||
return pinyin.getCamelChars(str).replace(/\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g, '')
|
||||
}
|
||||
return pinyin.getFullChars(str).replace(/\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g, '')
|
||||
}
|
||||
})
|
||||
|
||||
// 字符检索 传入检索值
|
||||
Object.defineProperty(String.prototype, 'filter', {
|
||||
writable: false,
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
value: function (input) {
|
||||
let str = this
|
||||
let en = str.toLowerCase().includes(input.toLowerCase())
|
||||
let zhFull = str.toPinyin().toLowerCase().includes(input.toLowerCase())
|
||||
let zhFirst = str.toPinyin(true).toLowerCase().includes(input.toLowerCase())
|
||||
return en || zhFull || zhFirst
|
||||
}
|
||||
})
|
||||
@@ -96,7 +96,7 @@ function createAxios<Data = any, T = ApiPromise<Data>>(
|
||||
response.data.code === 'A0000' ||
|
||||
response.data.type === 'application/json' ||
|
||||
Array.isArray(response.data) ||
|
||||
response.data.size
|
||||
response.data.size
|
||||
// ||
|
||||
// response.data.type === 'application/octet-stream' ||
|
||||
// response.data.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||
@@ -228,6 +228,37 @@ export function requestPayload(method: Method, data: anyObj) {
|
||||
}
|
||||
}
|
||||
}
|
||||
// 适配器, 用于适配不同的请求方式
|
||||
export function baseRequest(url, value = {}, method = 'post', options = {}) {
|
||||
url = sysConfig.API_URL + url
|
||||
if (method === 'post') {
|
||||
return service.post(url, value, options)
|
||||
} else if (method === 'get') {
|
||||
return service.get(url, { params: value, ...options })
|
||||
} else if (method === 'formdata') {
|
||||
// form-data表单提交的方式
|
||||
return service.post(url, qs.stringify(value), {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data'
|
||||
},
|
||||
...options
|
||||
})
|
||||
} else {
|
||||
// 其他请求方式,例如:put、delete
|
||||
return service({
|
||||
method: method,
|
||||
url: url,
|
||||
data: value,
|
||||
...options
|
||||
})
|
||||
}
|
||||
}
|
||||
// 模块内的请求, 会自动加上模块的前缀
|
||||
export const moduleRequest =
|
||||
(moduleUrl) =>
|
||||
(url, ...arg) => {
|
||||
return baseRequest(moduleUrl + url, ...arg)
|
||||
}
|
||||
|
||||
interface LoadingInstance {
|
||||
target: any
|
||||
|
||||
81
src/utils/themeUtil.js
Normal file
81
src/utils/themeUtil.js
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* Copyright [2022] [https://www.xiaonuo.vip]
|
||||
* Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||
* 2.请不要删除和修改Snowy源码头部的版权声明。
|
||||
* 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
|
||||
* 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
|
||||
* 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
||||
* 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
||||
*/
|
||||
import { generate } from '@ant-design/colors'
|
||||
import tool from '../utils/tool'
|
||||
import config from '../config'
|
||||
import { ThemeModeEnum } from './enum'
|
||||
|
||||
const changeColor = (newPrimaryColor, theme, darkClass = 'snowy-theme-dark') => {
|
||||
return new Promise((resolve) => {
|
||||
const themeEleId = 'snowy-theme-var'
|
||||
const themeEle = document.querySelector(`#${themeEleId}`)
|
||||
if (themeEle && themeEle.parentNode) {
|
||||
themeEle.parentNode.removeChild(themeEle)
|
||||
}
|
||||
const isRealDark = theme === ThemeModeEnum.REAL_DARK
|
||||
if (newPrimaryColor) {
|
||||
const colors = generate(newPrimaryColor, isRealDark ? { theme: 'dark' } : {})
|
||||
const rootClass = isRealDark ? `.${darkClass}` : ':root'
|
||||
const styleElement = document.createElement('style')
|
||||
styleElement.id = themeEleId
|
||||
styleElement.setAttribute('type', 'text/css')
|
||||
styleElement.innerHTML = `${rootClass}{${colors
|
||||
.map((c, i) => {
|
||||
return `--primary-${i + 1}:${c};`
|
||||
})
|
||||
.concat([`--primary-color:${newPrimaryColor};`])
|
||||
.join('')}}`
|
||||
document.head.appendChild(styleElement)
|
||||
} else {
|
||||
document.body.removeAttribute('snowy-theme')
|
||||
}
|
||||
if (isRealDark) {
|
||||
document.body.classList.add(darkClass)
|
||||
} else {
|
||||
document.body.classList.remove(darkClass)
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
|
||||
const loadLocalTheme = (localSetting) => {
|
||||
if (localSetting) {
|
||||
let { theme, themeColor } = localSetting
|
||||
themeColor = themeColor || config.COLOR
|
||||
theme = theme || config.THEME
|
||||
changeColor(themeColor, theme)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地保存的配置
|
||||
* @param loadTheme {boolean} 是否加载配置中的主题
|
||||
* @returns {Object}
|
||||
*/
|
||||
const getLocalSetting = (loadTheme) => {
|
||||
let localSetting = {}
|
||||
try {
|
||||
const theme = tool.data.get('SNOWY_THEME')
|
||||
const themeColor = tool.data.get('SNOWY_THEME_COLOR')
|
||||
localSetting = {
|
||||
theme,
|
||||
themeColor
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
if (loadTheme) {
|
||||
loadLocalTheme(localSetting)
|
||||
}
|
||||
return localSetting
|
||||
}
|
||||
|
||||
export { loadLocalTheme, getLocalSetting, changeColor }
|
||||
Reference in New Issue
Block a user