This commit is contained in:
张成
2025-10-28 14:10:05 +08:00
parent b101f49048
commit 5bea5f8c02
21 changed files with 105 additions and 151 deletions

View File

@@ -65,11 +65,9 @@ npm run dev
首先需要构建 admin-framework
```bash
# 生产构建(压缩,无 sourcemap
# 在项目根目录执行
cd ..
npm run build
# 开发构建(不压缩,有 sourcemap
npm run build:dev
```
### 2. 启动示例
@@ -109,16 +107,26 @@ const config = {
}
```
### 初始化框架
### 初始化框架(新版本 - 推荐)
```javascript
framework.install(Vue, {
config: config, // 配置对象
ViewUI: iview, // iView 实例
VueRouter: VueRouter, // Vue Router
Vuex: Vuex, // Vuex
createPersistedState: null, // Vuex 持久化插件(可选)
componentMap: {} // 自定义组件映射
// 引入 Admin Framework
import AdminFramework from '../../dist/admin-framework.js'
// 引入组件映射表
import componentMap from './router/component-map.js'
// 创建应用
const app = AdminFramework.createApp({
title: '我的管理系统',
apiUrl: 'http://localhost:9098/admin_api/',
componentMap: componentMap,
onReady() {
console.log('应用已准备就绪!')
}
})
// 挂载应用
app.$mount('#app')
```
## 内置功能
@@ -146,28 +154,30 @@ framework.install(Vue, {
### HTTP 请求
```javascript
// GET 请求
framework.http.get('/api/users').then(res => {
window.framework.http.get('/api/users').then(res => {
console.log(res.data)
})
// POST 请求
framework.http.post('/api/users', {
window.framework.http.post('/api/users', {
name: '张三',
age: 25
}).then(res => {
console.log(res.data)
})
// 在件中使用
this.$http.get('/api/users').then(res => {
console.log(res.data)
})
// 在 API 文件中使用
class UserServer {
async getList(params) {
return await window.framework.http.get('/api/users', params)
}
}
```
### 工具函数
```javascript
// 使用框架提供的工具函数
const tools = framework.tools
const tools = window.framework.tools
// 日期格式化
tools.formatDate(new Date(), 'yyyy-MM-dd HH:mm:ss')
@@ -185,16 +195,16 @@ tools.throttle(fn, 500)
### UI 工具
```javascript
// 使用 UI 工具
const uiTool = framework.uiTool
const uiTool = window.framework.uiTool
// 成功提示
window.framework.uiTool.success('操作成功')
window.framework.uiTool.success('操作成功')
// 错误提示
window.framework.uiTool.error('操作失败')
window.framework.uiTool.error('操作失败')
// 确认对话框
window.framework.uiTool.confirm('确定删除吗?').then(() => {
window.framework.uiTool.confirm('确定删除吗?').then(() => {
// 确认后的操作
})
```