更新记录

1.0.1(2026-06-05) 下载此版本

  • 添加 admin.request.js 管理模块
  • 添加 auth.request.js 认证模块
  • 添加 config.request.js 配置模块
  • 添加 rbac.request.js 权限控制模块
  • 添加 resource.request.js 资源管理模块
  • 完善 readme.md 使用文档
  • 添加 changelog.md 版本日志
  • 添加 license.md 许可证文件

1.0.0(2026-06-05) 下载此版本

  • 初始版本发布
  • 集成 uni.request 封装
  • 内置认证、RBAC、资源等请求模块
  • 支持自定义 API 映射
  • 支持配置 baseURL 和超时时间
  • 支持 Promise 和回调两种调用方式
  • 自动处理 Token 和 Locale 头部
  • 内置响应码处理(401、422等)

平台兼容性

uni-app(3.7.9)

Vue2 Vue3 Chrome Safari app-vue app-nvue Android iOS 鸿蒙
-
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
- - - - -

uni-app x(3.7.9)

Chrome Safari Android iOS 鸿蒙 微信小程序
- - - - -

dk-request 请求插件

一个功能完整的 uni-app 请求插件,包含认证、RBAC、资源等请求模块。

功能特性

  • 基于 uni.request 的封装
  • 支持 Promise 和回调函数两种调用方式
  • 自动处理 Token 和 Locale 头部
  • 内置响应码处理(401、422等)
  • 完整的认证、RBAC、资源等请求模块
  • 支持自定义 API 映射
  • 支持配置 baseURL 和超时时间

安装

在 HBuilderX 中导入本插件即可使用。

快速开始

在 main.js 中配置

import { setupRequest } from '@/uni_modules/dk-request/index';
import { App, User, setStoreInstances } from '@/uni_modules/dk-store/index';

// 设置 store 实例
setStoreInstances(App, User);

// 设置请求配置
setupRequest({
    baseURL: 'https://api.example.com',
    timeout: 30000,
});

使用基础请求

import { getRequest } from '@/uni_modules/dk-request/index';

const request = getRequest();

// GET 请求
request.get('/api/users', { page: 1 }).then(res => {
    console.log(res);
});

// POST 请求
request.post('/api/users', { name: 'John' }).then(res => {
    console.log(res);
});

// PUT 请求
request.put('/api/users/1', { name: 'John' }).then(res => {
    console.log(res);
});

// DELETE 请求
request.delete('/api/users/1').then(res => {
    console.log(res);
});

使用认证模块

import authRequest from '@/uni_modules/dk-request/js_sdk/auth.request';

// 获取验证码
authRequest.captcha().then(res => {
    console.log(res);
});

// 登录
authRequest.login({
    username: 'admin',
    password: '123456'
}, (data, code) => {
    console.log('登录成功', data);
}, (data, code) => {
    console.log('登录失败', data, code);
});

使用 RBAC 模块

import rbacRequest from '@/uni_modules/dk-request/js_sdk/rbac.request';

// 获取角色列表
rbacRequest.roles().then(res => {
    console.log(res);
});

// 添加角色
rbacRequest.addRole({ name: 'admin' }).then(res => {
    console.log(res);
});

// 获取权限
rbacRequest.permissions().then(res => {
    console.log(res);
});

使用资源模块

import resourceRequest from '@/uni_modules/dk-request/js_sdk/resource.request';

// 获取列表
resourceRequest.list('user', { page: 1 }).then(res => {
    console.log(res);
});

// 编辑
resourceRequest.edit('user', { id: 1 }).then(res => {
    console.log(res);
});

// 添加
resourceRequest.add('user', { name: 'John' }).then(res => {
    console.log(res);
});

// 删除
resourceRequest.del('user', { id: 1 }).then(res => {
    console.log(res);
});

API 参考

基础请求 (request.js)

import { request, config, RespCode } from '@/uni_modules/dk-request/js_sdk/request';

// 配置
config.baseURL = 'https://api.example.com';
config.timeout = 30000;

// 请求方法
request.get(url, data, options);
request.post(url, data, options);
request.put(url, data, options);
request.delete(url, data, options);

入口模块 (index.js)

import {
    getRequest,
    getApi,
    registerApis,
    setupRequest,
    requestConfig
} from '@/uni_modules/dk-request/index';

// 获取 API 路径
getApi('loginSubmit'); // 返回 'login/submit'

// 注册自定义 API
registerApis({
    customApi: 'custom/api/path'
});

Store 集成

import { setStoreInstances } from '@/uni_modules/dk-request/request';

// 设置 store 实例,用于获取 token 和 locale
setStoreInstances(AppStore, UserStore);

响应码常量

import { RespCode } from '@/uni_modules/dk-request/js_sdk/request';

RespCode.success; // 0
RespCode.unauthorized; // 401
RespCode.validate; // 422
RespCode.validate2; // 4001

内置请求模块

模块 说明
admin.request.js 管理员相关请求
auth.request.js 认证相关请求(登录、验证码等)
config.request.js 配置相关请求
rbac.request.js RBAC 权限管理请求
resource.request.js 资源 CRUD 请求

目录结构

uni_modules/dk-request/
├── uniCloud/
├── components/
├── utssdk/
├── hybrid/
├── pages/
├── static/
├── wxcomponents/
├── js_sdk/
│   ├── index.js           # 入口文件
│   ├── request.js         # 核心请求模块
│   ├── admin.request.js   # 管理员请求
│   ├── auth.request.js    # 认证请求
│   ├── config.request.js  # 配置请求
│   ├── rbac.request.js    # RBAC 请求
│   └── resource.request.js # 资源请求
├── license.md
├── package.json
├── readme.md
└── changelog.md

兼容性

  • HBuilderX 3.1.0+
  • uni-app 4.1.0+
  • uni-app x 4.2.0+

更新日志

changelog.md

许可证

license.md

隐私、权限声明

1. 本插件需要申请的系统权限列表:

none

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

none

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

none

许可协议

许可证

MIT License

Copyright (c) 2026 kordar

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

暂无用户评论。