uniapp 底层
This commit is contained in:
parent
00a9b9ede0
commit
04f9d7eb36
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
# 请求域名
|
||||
VITE_APP_BASE_URL='https://likeadmin-java.yixiangonline.com'
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/* eslint-env node */
|
||||
require('@rushstack/eslint-patch/modern-module-resolution')
|
||||
|
||||
module.exports = {
|
||||
root: true,
|
||||
extends: [
|
||||
'plugin:vue/vue3-essential',
|
||||
'eslint:recommended',
|
||||
'@vue/eslint-config-typescript/recommended',
|
||||
'@vue/eslint-config-prettier'
|
||||
],
|
||||
rules: {
|
||||
'prettier/prettier': [
|
||||
'warn',
|
||||
{
|
||||
semi: false,
|
||||
singleQuote: true,
|
||||
printWidth: 100,
|
||||
proseWrap: 'preserve',
|
||||
bracketSameLine: false,
|
||||
endOfLine: 'lf',
|
||||
tabWidth: 4,
|
||||
useTabs: false,
|
||||
trailingComma: 'none'
|
||||
}
|
||||
],
|
||||
'vue/multi-word-component-names': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/ban-ts-comment': 'off',
|
||||
'no-undef': 'off',
|
||||
'vue/prefer-import-from-vue': 'off',
|
||||
'no-prototype-builtins': 'off',
|
||||
'prefer-spread': 'off',
|
||||
'@typescript-eslint/no-non-null-assertion': 'off',
|
||||
'@typescript-eslint/no-non-null-asserted-optional-chain': 'off'
|
||||
},
|
||||
globals: {}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
.DS_Store
|
||||
dist
|
||||
dist-ssr
|
||||
coverage
|
||||
*.local
|
||||
|
||||
|
||||
/cypress/videos/
|
||||
/cypress/screenshots/
|
||||
|
||||
# Editor directories and files
|
||||
.idea
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<script>
|
||||
var coverSupport = 'CSS' in window && typeof CSS.supports === 'function' && (CSS.supports('top: env(a)') ||
|
||||
CSS.supports('top: constant(a)'))
|
||||
document.write(
|
||||
'<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0' +
|
||||
(coverSupport ? ', viewport-fit=cover' : '') + '" />')
|
||||
</script>
|
||||
<title></title>
|
||||
<!--preload-links-->
|
||||
<!--app-context-->
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"><!--app-html--></div>
|
||||
<script type="module" src="/src/main.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,79 @@
|
|||
{
|
||||
"name": "uni-preset-vue",
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"dev:app": "uni -p app",
|
||||
"dev:custom": "uni -p",
|
||||
"dev:h5": "uni",
|
||||
"dev:h5:ssr": "uni --ssr",
|
||||
"dev:mp-alipay": "uni -p mp-alipay",
|
||||
"dev:mp-baidu": "uni -p mp-baidu",
|
||||
"dev:mp-kuaishou": "uni -p mp-kuaishou",
|
||||
"dev:mp-lark": "uni -p mp-lark",
|
||||
"dev:mp-qq": "uni -p mp-qq",
|
||||
"dev:mp-toutiao": "uni -p mp-toutiao",
|
||||
"dev:mp-weixin": "uni -p mp-weixin",
|
||||
"dev:quickapp-webview": "uni -p quickapp-webview",
|
||||
"dev:quickapp-webview-huawei": "uni -p quickapp-webview-huawei",
|
||||
"dev:quickapp-webview-union": "uni -p quickapp-webview-union",
|
||||
"build:app": "uni build -p app",
|
||||
"build:custom": "uni build -p",
|
||||
"build:h5": "uni build",
|
||||
"build:h5:ssr": "uni build --ssr",
|
||||
"build:mp-alipay": "uni build -p mp-alipay",
|
||||
"build:mp-baidu": "uni build -p mp-baidu",
|
||||
"build:mp-kuaishou": "uni build -p mp-kuaishou",
|
||||
"build:mp-lark": "uni build -p mp-lark",
|
||||
"build:mp-qq": "uni build -p mp-qq",
|
||||
"build:mp-toutiao": "uni build -p mp-toutiao",
|
||||
"build:mp-weixin": "uni build -p mp-weixin",
|
||||
"build:quickapp-webview": "uni build -p quickapp-webview",
|
||||
"build:quickapp-webview-huawei": "uni build -p quickapp-webview-huawei",
|
||||
"build:quickapp-webview-union": "uni build -p quickapp-webview-union",
|
||||
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
|
||||
},
|
||||
"dependencies": {
|
||||
"@dcloudio/uni-app": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-app-plus": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-components": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-h5": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-mp-alipay": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-mp-baidu": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-mp-kuaishou": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-mp-lark": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-mp-qq": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-mp-toutiao": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-mp-weixin": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-quickapp-webview": "^3.0.0-alpha-3050520220824001",
|
||||
"lodash-es": "^4.17.21",
|
||||
"pinia": "^2.0.20",
|
||||
"uview-plus": "^3.1.6",
|
||||
"vconsole": "^3.14.6",
|
||||
"vue": "^3.2.37",
|
||||
"vue-i18n": "^9.2.2",
|
||||
"z-paging": "^2.3.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@dcloudio/types": "^3.0.13",
|
||||
"@dcloudio/uni-automator": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-cli-shared": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/uni-stacktracey": "^3.0.0-alpha-3050520220824001",
|
||||
"@dcloudio/vite-plugin-uni": "^3.0.0-alpha-3050520220824001",
|
||||
"@rushstack/eslint-patch": "^1.1.4",
|
||||
"@types/lodash-es": "^4.17.6",
|
||||
"@types/node": "^18.7.13",
|
||||
"@vue/eslint-config-prettier": "^7.0.0",
|
||||
"@vue/eslint-config-typescript": "^11.0.0",
|
||||
"autoprefixer": "^10.4.8",
|
||||
"eslint": "^8.22.0",
|
||||
"eslint-plugin-vue": "^9.4.0",
|
||||
"postcss": "^8.4.16",
|
||||
"postcss-rem-to-responsive-pixel": "^5.1.3",
|
||||
"prettier": "^2.7.1",
|
||||
"sass": "^1.54.5",
|
||||
"tailwindcss": "^3.1.8",
|
||||
"typescript": "^4.7.4",
|
||||
"vite": "^2.9.14",
|
||||
"weapp-tailwindcss-webpack-plugin": "^1.7.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<script setup lang="ts">
|
||||
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
|
||||
import request from './utils/request'
|
||||
onLaunch(() => {
|
||||
console.log('App Launch')
|
||||
})
|
||||
onShow(() => {
|
||||
console.log('App Show')
|
||||
})
|
||||
onHide(() => {
|
||||
console.log('App Hide')
|
||||
})
|
||||
</script>
|
||||
<style lang="scss">
|
||||
/* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
|
||||
@import 'uview-plus/index.scss';
|
||||
</style>
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
//菜单主题类型
|
||||
export enum ThemeEnum {
|
||||
LIGHT = 'light',
|
||||
DARK = 'dark'
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
// 本地缓冲key
|
||||
|
||||
//token
|
||||
export const TOKEN_KEY = 'token'
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
export enum ContentTypeEnum {
|
||||
// json
|
||||
JSON = 'application/json;charset=UTF-8',
|
||||
// form-data 上传资源(图片,视频)
|
||||
FORM_DATA = 'multipart/form-data;charset=UTF-8'
|
||||
}
|
||||
|
||||
export enum RequestMethodsEnum {
|
||||
GET = 'GET',
|
||||
POST = 'POST'
|
||||
}
|
||||
|
||||
export enum RequestCodeEnum {
|
||||
SUCCESS = 200, //成功
|
||||
FAILED = 300, // 失败
|
||||
PARAMS_VALID_ERROR = 310, //参数校验错误
|
||||
PARAMS_TYPE_ERROR = 311, //参数类型错误
|
||||
REQUEST_METHOD_ERROR = 312, //请求方法错误
|
||||
ASSERT_ARGUMENT_ERROR = 313, //断言参数错误
|
||||
ASSERT_MYBATIS_ERROR = 314, //断言mybatis错误
|
||||
LOGIN_ACCOUNT_ERROR = 330, //登陆账号或密码错误
|
||||
LOGIN_DISABLE_ERROR = 331, //登陆账号已被禁用
|
||||
TOKEN_EMPTY = 332, // TOKEN参数为空
|
||||
TOKEN_INVALID = 333, // TOKEN参数无效
|
||||
NO_PERMISSTION = 403, //无相关权限
|
||||
REQUEST_404_ERROR = 404, //请求接口不存在
|
||||
SYSTEM_ERROR = 500 //系统错误
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import { createSSRApp } from 'vue'
|
||||
// import { createPinia } from 'pinia'
|
||||
import App from './App.vue'
|
||||
import plugins from './plugins'
|
||||
import './styles/index.scss'
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App)
|
||||
console.log(app.config.globalProperties)
|
||||
app.use(plugins)
|
||||
return {
|
||||
app
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
{
|
||||
"name": "",
|
||||
"appid": "",
|
||||
"description": "",
|
||||
"versionName": "1.0.0",
|
||||
"versionCode": "100",
|
||||
"transformPx": false,
|
||||
/* 5+App特有相关 */
|
||||
"app-plus": {
|
||||
"usingComponents": true,
|
||||
"nvueStyleCompiler": "uni-app",
|
||||
"compilerVersion": 3,
|
||||
"splashscreen": {
|
||||
"alwaysShowBeforeRender": true,
|
||||
"waiting": true,
|
||||
"autoclose": true,
|
||||
"delay": 0
|
||||
},
|
||||
/* 模块配置 */
|
||||
"modules": {},
|
||||
/* 应用发布信息 */
|
||||
"distribute": {
|
||||
/* android打包配置 */
|
||||
"android": {
|
||||
"permissions": [
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_LOGS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera.autofocus\"/>",
|
||||
"<uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CAMERA\"/>",
|
||||
"<uses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>",
|
||||
"<uses-permission android:name=\"android.permission.READ_PHONE_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WAKE_LOCK\"/>",
|
||||
"<uses-permission android:name=\"android.permission.FLASHLIGHT\"/>",
|
||||
"<uses-feature android:name=\"android.hardware.camera\"/>",
|
||||
"<uses-permission android:name=\"android.permission.WRITE_SETTINGS\"/>"
|
||||
]
|
||||
},
|
||||
/* ios打包配置 */
|
||||
"ios": {},
|
||||
/* SDK配置 */
|
||||
"sdkConfigs": {}
|
||||
}
|
||||
},
|
||||
/* 快应用特有相关 */
|
||||
"quickapp": {},
|
||||
/* 小程序特有相关 */
|
||||
"mp-weixin": {
|
||||
"appid": "wx65b3824de0b3d3b0",
|
||||
"setting": {
|
||||
"urlCheck": false
|
||||
},
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-alipay": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-baidu": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"mp-toutiao": {
|
||||
"usingComponents": true
|
||||
},
|
||||
"uniStatistics": {
|
||||
"enable": false
|
||||
},
|
||||
"vueVersion": "3"
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
{
|
||||
"pages": [
|
||||
{
|
||||
"path": "pages/index/index",
|
||||
"style": {
|
||||
"navigationBarTitleText": "首页"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/news/news",
|
||||
"style": {
|
||||
"navigationBarTitleText": "资讯"
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "pages/user/user",
|
||||
"style": {
|
||||
"navigationBarTitleText": "个人中心"
|
||||
}
|
||||
}
|
||||
],
|
||||
"globalStyle": {
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarTitleText": "商城",
|
||||
"navigationBarBackgroundColor": "#FFFFFF",
|
||||
"backgroundColor": "#F8F8F8"
|
||||
},
|
||||
"tabBar": {
|
||||
"color": "#7A7E83",
|
||||
"selectedColor": "#3cc51f",
|
||||
"borderStyle": "black",
|
||||
"backgroundColor": "#ffffff",
|
||||
"list": [
|
||||
{
|
||||
"pagePath": "pages/index/index",
|
||||
"text": "首页"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/news/news",
|
||||
"text": "资讯"
|
||||
},
|
||||
{
|
||||
"pagePath": "pages/user/user",
|
||||
"text": "我的"
|
||||
}
|
||||
]
|
||||
},
|
||||
"easycom": {
|
||||
"custom": {
|
||||
"^u-(.*)": "uview-plus/components/u-$1/u-$1.vue",
|
||||
"^(?!z-paging-refresh|z-paging-load-more)z-paging(.*)": "z-paging/components/z-paging$1/z-paging$1.vue"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<template>
|
||||
<view class="content">
|
||||
<z-paging ref="paging" v-model="dataList">
|
||||
<!-- 之后-vue3 -->
|
||||
<template v-slot:top>
|
||||
<view>我是固定在顶部的view</view>
|
||||
</template>
|
||||
</z-paging>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
|
||||
const dataList = ref([])
|
||||
</script>
|
||||
|
||||
<style></style>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<template>
|
||||
<view class="content">资讯</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts"></script>
|
||||
|
||||
<style></style>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<template>
|
||||
<view class="content">个人设置</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts"></script>
|
||||
|
||||
<style></style>
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import { isFunction } from '@vue/shared'
|
||||
import { App } from 'vue'
|
||||
const modules = import.meta.globEager('./modules/**/*.ts')
|
||||
|
||||
export default {
|
||||
install: (app: App) => {
|
||||
for (const module of Object.values(modules)) {
|
||||
const fun = module.default
|
||||
isFunction(fun) && fun(app)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
import uviewPlus from 'uview-plus'
|
||||
import { App } from 'vue'
|
||||
|
||||
export default (app: App) => {
|
||||
uni.$u.setConfig({
|
||||
// 修改$u.config对象的属性
|
||||
config: {
|
||||
// 修改默认单位为rpx,相当于执行 uni.$u.config.unit = 'rpx'
|
||||
unit: 'rpx'
|
||||
},
|
||||
// 修改$u.props对象的属性
|
||||
props: {
|
||||
// 修改radio组件的size参数的默认值,相当于执行 uni.$u.props.radio.size = 30
|
||||
radio: {
|
||||
size: 15
|
||||
}
|
||||
}
|
||||
})
|
||||
app.use(uviewPlus)
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
// #ifdef H5
|
||||
// 提交前需要注释 本地调试使用
|
||||
import Vconsole from 'vconsole'
|
||||
// #endif
|
||||
|
||||
export default () => {
|
||||
// #ifdef H5
|
||||
const vConsole = new Vconsole()
|
||||
return vConsole
|
||||
// #endif
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
|
|
@ -0,0 +1,2 @@
|
|||
@import './tailwind.css';
|
||||
@import './public.scss';
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
/* #ifdef H5 */
|
||||
@tailwind base;
|
||||
/* #endif */
|
||||
|
||||
@tailwind utilities;
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
|
||||
/* 颜色变量 */
|
||||
|
||||
/* 行为相关颜色 */
|
||||
$uni-color-primary: #007aff;
|
||||
$uni-color-success: #4cd964;
|
||||
$uni-color-warning: #f0ad4e;
|
||||
$uni-color-error: #dd524d;
|
||||
|
||||
/* 文字基本颜色 */
|
||||
$uni-text-color: #333; //基本色
|
||||
$uni-text-color-inverse: #fff; //反色
|
||||
$uni-text-color-grey: #999; //辅助灰色,如加载更多的提示信息
|
||||
$uni-text-color-placeholder: #808080;
|
||||
$uni-text-color-disable: #c0c0c0;
|
||||
|
||||
/* 背景颜色 */
|
||||
$uni-bg-color: #ffffff;
|
||||
$uni-bg-color-grey: #f8f8f8;
|
||||
$uni-bg-color-hover: #f1f1f1; //点击状态颜色
|
||||
$uni-bg-color-mask: rgba(0, 0, 0, 0.4); //遮罩颜色
|
||||
|
||||
/* 边框颜色 */
|
||||
$uni-border-color: #c8c7cc;
|
||||
|
||||
/* 尺寸变量 */
|
||||
|
||||
/* 文字尺寸 */
|
||||
$uni-font-size-sm: 24rpx;
|
||||
$uni-font-size-base: 28rpx;
|
||||
$uni-font-size-lg: 32rpx;
|
||||
|
||||
/* 图片尺寸 */
|
||||
$uni-img-size-sm: 40rpx;
|
||||
$uni-img-size-base: 52rpx;
|
||||
$uni-img-size-lg: 80rpx;
|
||||
|
||||
/* Border Radius */
|
||||
$uni-border-radius-sm: 4rpx;
|
||||
$uni-border-radius-base: 6rpx;
|
||||
$uni-border-radius-lg: 12rpx;
|
||||
$uni-border-radius-circle: 50%;
|
||||
|
||||
/* 水平间距 */
|
||||
$uni-spacing-row-sm: 10px;
|
||||
$uni-spacing-row-base: 20rpx;
|
||||
$uni-spacing-row-lg: 30rpx;
|
||||
|
||||
/* 垂直间距 */
|
||||
$uni-spacing-col-sm: 8rpx;
|
||||
$uni-spacing-col-base: 16rpx;
|
||||
$uni-spacing-col-lg: 24rpx;
|
||||
|
||||
/* 透明度 */
|
||||
$uni-opacity-disabled: 0.3; // 组件禁用态的透明度
|
||||
|
||||
/* 文章场景相关 */
|
||||
$uni-color-title: #2c405a; // 文章标题颜色
|
||||
$uni-font-size-title: 40rpx;
|
||||
$uni-color-subtitle: #555555; // 二级标题颜色
|
||||
$uni-font-size-subtitle: 36rpx;
|
||||
$uni-color-paragraph: #3f536e; // 文章段落颜色
|
||||
$uni-font-size-paragraph: 30rpx;
|
||||
@import 'uview-plus/theme.scss';
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
import { TOKEN_KEY } from '@/enums/cacheEnums'
|
||||
import cache from './cache'
|
||||
|
||||
export function getToken() {
|
||||
return cache.get(TOKEN_KEY)
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
const cache = {
|
||||
key: 'app_',
|
||||
//设置缓存(expire为缓存时效)
|
||||
set(key: string, value: any, expire?: string) {
|
||||
key = this.getKey(key)
|
||||
let data: any = {
|
||||
expire: expire ? this.time() + expire : '',
|
||||
value
|
||||
}
|
||||
|
||||
if (typeof data === 'object') {
|
||||
data = JSON.stringify(data)
|
||||
}
|
||||
try {
|
||||
window.localStorage.setItem(key, data)
|
||||
} catch (e) {
|
||||
return null
|
||||
}
|
||||
},
|
||||
get(key: string) {
|
||||
key = this.getKey(key)
|
||||
try {
|
||||
const data = window.localStorage.getItem(key)
|
||||
if (!data) {
|
||||
return null
|
||||
}
|
||||
const { value, expire } = JSON.parse(data)
|
||||
if (expire && expire < this.time()) {
|
||||
window.localStorage.removeItem(key)
|
||||
return null
|
||||
}
|
||||
return value
|
||||
} catch (e) {
|
||||
return null
|
||||
}
|
||||
},
|
||||
//获取当前时间
|
||||
time() {
|
||||
return Math.round(new Date().getTime() / 1000)
|
||||
},
|
||||
remove(key: string) {
|
||||
key = this.getKey(key)
|
||||
window.localStorage.removeItem(key)
|
||||
},
|
||||
getKey(key: string) {
|
||||
return this.key + key
|
||||
}
|
||||
}
|
||||
|
||||
export default cache
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
import { RequestTask } from './type'
|
||||
|
||||
const cancelerMap = new Map<string, RequestTask>()
|
||||
|
||||
export class RequestCancel {
|
||||
private static instance?: RequestCancel
|
||||
|
||||
static createInstance() {
|
||||
return this.instance ?? (this.instance = new RequestCancel())
|
||||
}
|
||||
add(url: string, requestTask: RequestTask) {
|
||||
this.remove(url)
|
||||
if (!cancelerMap.has(url)) {
|
||||
cancelerMap.set(url, requestTask)
|
||||
}
|
||||
}
|
||||
remove(url: string) {
|
||||
if (cancelerMap.has(url)) {
|
||||
const requestTask = cancelerMap.get(url)
|
||||
requestTask && requestTask.abort()
|
||||
cancelerMap.delete(url)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const requestCancel = RequestCancel.createInstance()
|
||||
|
||||
export default requestCancel
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
import { merge } from 'lodash-es'
|
||||
import { isFunction } from '@vue/shared'
|
||||
import { HttpRequestOptions, RequestConfig, RequestOptions } from './type'
|
||||
import { RequestMethodsEnum } from '@/enums/requestEnums'
|
||||
import requestCancel from './cancel'
|
||||
|
||||
export default class HttpRequest {
|
||||
private readonly options: HttpRequestOptions
|
||||
constructor(options: HttpRequestOptions) {
|
||||
this.options = options
|
||||
}
|
||||
|
||||
/**
|
||||
* @description get请求
|
||||
*/
|
||||
get<T = any>(options: RequestOptions, config?: Partial<RequestConfig>): Promise<T> {
|
||||
return this.request({ ...options, method: RequestMethodsEnum.GET }, config)
|
||||
}
|
||||
|
||||
/**
|
||||
* @description post请求
|
||||
*/
|
||||
post<T = any>(options: RequestOptions, config?: Partial<RequestConfig>): Promise<T> {
|
||||
return this.request({ ...options, method: RequestMethodsEnum.POST }, config)
|
||||
}
|
||||
/**
|
||||
* @description 请求函数
|
||||
*/
|
||||
async request(options: RequestOptions, config?: Partial<RequestConfig>): Promise<any> {
|
||||
let mergeOptions: RequestOptions = merge({}, this.options.requestOptions, options)
|
||||
const mergeConfig: RequestConfig = merge({}, this.options, config)
|
||||
const { requestInterceptorsHook, responseInterceptorsHook, responseInterceptorsCatchHook } =
|
||||
mergeConfig.requestHooks || {}
|
||||
if (requestInterceptorsHook && isFunction(requestInterceptorsHook)) {
|
||||
mergeOptions = requestInterceptorsHook(options, mergeConfig)
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
const requestTask = uni.request({
|
||||
...mergeOptions,
|
||||
success(response) {
|
||||
if (responseInterceptorsHook && isFunction(responseInterceptorsHook)) {
|
||||
try {
|
||||
response = responseInterceptorsHook(response, mergeConfig)
|
||||
resolve(response)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
return
|
||||
}
|
||||
resolve(response)
|
||||
},
|
||||
fail(err) {
|
||||
if (
|
||||
responseInterceptorsCatchHook &&
|
||||
isFunction(responseInterceptorsCatchHook)
|
||||
) {
|
||||
reject(responseInterceptorsCatchHook(err, mergeConfig))
|
||||
return
|
||||
}
|
||||
reject(err)
|
||||
},
|
||||
complete() {
|
||||
requestCancel.remove(options.url)
|
||||
}
|
||||
})
|
||||
const { ignoreCancel } = mergeConfig
|
||||
!ignoreCancel && requestCancel.add(options.url, requestTask)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,87 @@
|
|||
import HttpRequest from './http'
|
||||
import { merge } from 'lodash-es'
|
||||
import { HttpRequestOptions, RequestHooks } from './type'
|
||||
import { getToken } from '../auth'
|
||||
import { RequestCodeEnum } from '@/enums/requestEnums'
|
||||
|
||||
const requestHooks: RequestHooks = {
|
||||
requestInterceptorsHook(options, config) {
|
||||
const { urlPrefix, baseUrl, withToken } = config
|
||||
options.header = options.header ?? {}
|
||||
if (urlPrefix) {
|
||||
options.url = `${urlPrefix}${options.url}`
|
||||
}
|
||||
if (baseUrl) {
|
||||
options.url = `${baseUrl}${options.url}`
|
||||
}
|
||||
// 添加token
|
||||
if (withToken) {
|
||||
const token = getToken()
|
||||
options.header.token = token
|
||||
}
|
||||
return options
|
||||
},
|
||||
responseInterceptorsHook(response, config) {
|
||||
const { isTransformResponse, isReturnDefaultResponse } = config
|
||||
|
||||
//返回默认响应,当需要获取响应头及其他数据时可使用
|
||||
if (isReturnDefaultResponse) {
|
||||
return response
|
||||
}
|
||||
// 是否需要对数据进行处理
|
||||
if (!isTransformResponse) {
|
||||
return response.data
|
||||
}
|
||||
const { code, data, msg } = response.data as any
|
||||
switch (code) {
|
||||
case RequestCodeEnum.SUCCESS:
|
||||
return data
|
||||
|
||||
case RequestCodeEnum.PARAMS_TYPE_ERROR:
|
||||
case RequestCodeEnum.PARAMS_VALID_ERROR:
|
||||
case RequestCodeEnum.REQUEST_METHOD_ERROR:
|
||||
case RequestCodeEnum.ASSERT_ARGUMENT_ERROR:
|
||||
case RequestCodeEnum.ASSERT_MYBATIS_ERROR:
|
||||
case RequestCodeEnum.LOGIN_ACCOUNT_ERROR:
|
||||
case RequestCodeEnum.LOGIN_DISABLE_ERROR:
|
||||
case RequestCodeEnum.NO_PERMISSTION:
|
||||
case RequestCodeEnum.FAILED:
|
||||
case RequestCodeEnum.SYSTEM_ERROR:
|
||||
return Promise.reject(data)
|
||||
|
||||
case RequestCodeEnum.TOKEN_INVALID:
|
||||
case RequestCodeEnum.TOKEN_EMPTY:
|
||||
return Promise.reject()
|
||||
|
||||
default:
|
||||
return data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const defaultOptions: HttpRequestOptions = {
|
||||
requestOptions: {
|
||||
timeout: 10 * 1000
|
||||
},
|
||||
baseUrl: 'https://likeadmin-java.yixiangonline.com',
|
||||
//是否返回默认的响应
|
||||
isReturnDefaultResponse: false,
|
||||
// 需要对返回数据进行处理
|
||||
isTransformResponse: true,
|
||||
// 接口拼接地址
|
||||
urlPrefix: '/api',
|
||||
// 忽略重复请求
|
||||
ignoreCancel: false,
|
||||
// 是否携带token
|
||||
withToken: true,
|
||||
requestHooks: requestHooks
|
||||
}
|
||||
|
||||
function createRequest(opt?: HttpRequestOptions) {
|
||||
return new HttpRequest(
|
||||
// 深度合并
|
||||
merge(defaultOptions, opt || {})
|
||||
)
|
||||
}
|
||||
const request = createRequest()
|
||||
export default request
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
export type RequestOptions = UniApp.RequestOptions
|
||||
export type ResponseResult = UniApp.RequestSuccessCallbackResult
|
||||
export type ResponseError = UniApp.GeneralCallbackResult
|
||||
export type RequestTask = UniApp.RequestTask
|
||||
export interface HttpRequestOptions extends RequestConfig {
|
||||
requestOptions: Partial<RequestOptions>
|
||||
}
|
||||
|
||||
export interface RequestConfig {
|
||||
baseUrl: string
|
||||
requestHooks: RequestHooks
|
||||
isReturnDefaultResponse: boolean
|
||||
isTransformResponse: boolean
|
||||
urlPrefix: string
|
||||
ignoreCancel: boolean
|
||||
withToken: boolean
|
||||
}
|
||||
|
||||
export interface RequestHooks {
|
||||
requestInterceptorsHook?(options: RequestOptions, config: RequestConfig): RequestOptions
|
||||
responseInterceptorsHook?(response: ResponseResult, config: RequestConfig): any
|
||||
responseInterceptorsCatchHook?(error: ResponseError, config: RequestConfig): any
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
/** @type {import('tailwindcss').Config} */
|
||||
module.exports = {
|
||||
content: ['./index.html', './src/**/*.{vue,js,ts,jsx,tsx}'],
|
||||
theme: {
|
||||
extend: {}
|
||||
},
|
||||
plugins: []
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "esnext",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node",
|
||||
"strict": true,
|
||||
"jsx": "preserve",
|
||||
"sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true,
|
||||
"lib": ["esnext", "dom"],
|
||||
"types": ["@dcloudio/types"],
|
||||
"isolatedModules": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue", "typings/**/*.d.ts"]
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
/// <reference types="vite/client" />
|
||||
|
||||
declare module '*.vue' {
|
||||
import { DefineComponent } from 'vue'
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
|
||||
const component: DefineComponent<{}, {}, any>
|
||||
export default component
|
||||
}
|
||||
|
||||
declare module 'uview-plus'
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
interface Uni {
|
||||
$u: any
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
import { defineConfig } from 'vite'
|
||||
import uni from '@dcloudio/vite-plugin-uni'
|
||||
import postcssPlugins from './vite/postcss'
|
||||
import { wtwp } from './vite/wtwp'
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [uni(), wtwp()],
|
||||
css: {
|
||||
postcss: {
|
||||
plugins: postcssPlugins
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
import tailwindcss from 'tailwindcss'
|
||||
import autoprefixer from 'autoprefixer'
|
||||
import postcssRemToResponsivePixel from 'postcss-rem-to-responsive-pixel'
|
||||
import postcssWeappTailwindcssRename from 'weapp-tailwindcss-webpack-plugin/postcss'
|
||||
import { Plugin } from 'postcss'
|
||||
const postcssPlugin = [
|
||||
autoprefixer(),
|
||||
tailwindcss(),
|
||||
postcssRemToResponsivePixel({
|
||||
rootValue: 32,
|
||||
propList: ['*'],
|
||||
transformUnit: 'rpx'
|
||||
}),
|
||||
postcssWeappTailwindcssRename()
|
||||
]
|
||||
|
||||
export default postcssPlugin as Plugin[]
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
const isH5 = process.env.UNI_PLATFORM === 'h5'
|
||||
const isApp = process.env.UNI_PLATFORM === 'app'
|
||||
const weappTailwindcssDisabled = isH5 || isApp
|
||||
import vwt from 'weapp-tailwindcss-webpack-plugin/vite'
|
||||
|
||||
export function wtwp() {
|
||||
return weappTailwindcssDisabled ? undefined : vwt()
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue