Skip to content

Commit

Permalink
0.0.4 (#281)
Browse files Browse the repository at this point in the history
* 先去掉 bk-PaaS 中的其他内容,只保留 paas-ce/lesscode 目录

* init lesscode

* add .pre-commit-config.yaml

* test

* test

* add pre-commit & update dev_install doc & add bk-PaaS doc

* typo

* up dev_install doc

* up dev_install doc

* up dev_install doc

* up dev_install doc

* up .pre-commit-config.yaml

* up comment info

* add .pre-commit-config.yaml to ignore

* feature: 组件属性配置类型提示首字母大写

* 可视化布局 => 可视化开发

* 可视化布局 => 可视化开发

* 可视化布局 => 可视化开发

* Lesscode update doc (#199)

* ignore .idea

* update bk-magic-vue version (for bk-color-picker select '')

* 组件属性提示增加 tips 配置字段

* button 按钮组件使用说明

* text 按钮组件使用说明

* image 图片组件使用说明

* input 输入框组件使用说明

* events 配置数据结构优化 ['change'] ==> [{ name: 'change', tips: ''}]

* 组件使用帮助 tips

* 帮助文档页面移除单个组件导航

* 帮助文档:栅格布局

* merge #201

* merge manually from #201

* merge manually from #201 (#202)

* merge #201

* merge manually from #201

* 添加快捷操作功能 (#205)

* 增加chart图表 (#206)

* 增加chart图表

* fix冲突

* 删除consolelog

* 更新图标库

* merge manually from #203

* merge manually from #203 (#212)

* 拖拽快捷操作支持Mac Command键 (#213)

* 添加快捷操作功能

* 拖拽快捷键支持Mac Command键

* 修改快捷操作说明

* fix some bug

* 修复 charts-line options.tips 小问题

* 修复 charts-line options.tips 小问题 (#215)

* 修复刷新页面时,没有选中组件但右侧面板会显示 grid 属性的问题

* 【lesscode】修复刷新页面时,没有选中组件但右侧面板会显示 grid 属性的问题 (#216)

* merge #201

* merge manually from #201

* merge manually from #203

* fix some bug

* 修复 charts-line options.tips 小问题

* 修复刷新页面时,没有选中组件但右侧面板会显示 grid 属性的问题

* 修复 chart 组件样式被覆盖的问题

* 【lesscode】修复 chart 组件样式被覆盖的问题 (#217)

* merge #201

* merge manually from #201

* merge manually from #203

* fix some bug

* 修复 charts-line options.tips 小问题

* 修复刷新页面时,没有选中组件但右侧面板会显示 grid 属性的问题

* 修复 chart 组件样式被覆盖的问题

* fix图表问题 (#218)

* 增加chart图表

* fix冲突

* 删除consolelog

* 更新图标库

* 同步新的lesscode-develop,fix图表bug

* 修改快捷操作 (#219)

* 添加快捷操作功能

* 拖拽快捷键支持Mac Command键

* 修改快捷操作说明

* 修复剪切快捷操作,修改快捷操作说明

* 修改快捷操作 (#220)

* 添加快捷操作功能

* 拖拽快捷键支持Mac Command键

* 修改快捷操作说明

* 修复剪切快捷操作,修改快捷操作说明

* 兼容数据为空的情况

* 兼容数据为空的情况

Co-authored-by: ielgnaw <[email protected]>

* 体验 bug 修复

* 【lesscode】体验 bug 修复 (#221)

* merge #201

* merge manually from #201

* merge manually from #203

* fix some bug

* 修复 charts-line options.tips 小问题

* 修复刷新页面时,没有选中组件但右侧面板会显示 grid 属性的问题

* 修复 chart 组件样式被覆盖的问题

* 体验 bug 修复

* 修改快捷操作判断 (#222)

* 添加快捷操作功能

* 拖拽快捷键支持Mac Command键

* 修改快捷操作说明

* 修复剪切快捷操作,修改快捷操作说明

* 兼容数据为空的情况

* 兼容数据为空的情况

* 仅在选中拖拽区域触发快捷操作

* 修改判断是否在拖拽区域

* 修复体验问题

* 修复体验问题 (#223)

* 增加backspace快捷删除 (#224)

* 添加快捷操作功能

* 拖拽快捷键支持Mac Command键

* 修改快捷操作说明

* 修复剪切快捷操作,修改快捷操作说明

* 兼容数据为空的情况

* 兼容数据为空的情况

* 仅在选中拖拽区域触发快捷操作

* 修改判断是否在拖拽区域

* 增加backspace快速删除
修改快捷面版样式

* 画布仅剩一个 grid 时,不允许删除;增加清空 grid 操作

* 画布仅剩一个 grid 时,不允许删除;增加清空 grid 操作 (#225)

* 修复 clone grid 时,右侧面板没有默认选中的问题;更新日志

* 修复 clone grid 时,右侧面板没有默认选中的问题;更新日志 (#226)

* 文案

* 文案 (#227)

* 后端orm采用TypeORM (#229)

* 后端采用typeorm

* orm添加migration (#230)

* 修改数据迁移表

* 添加初始化脚本 (#233)

* 增加data-base.js.example

* 添加初始化SQL

* 修改初始化脚本

* 新增项目级别页面布局和项目列表页UI (#232)

* 新增数据库部署文档 (#234)

* 添加快捷操作功能

* 拖拽快捷键支持Mac Command键

* 修改快捷操作说明

* 修复剪切快捷操作,修改快捷操作说明

* 兼容数据为空的情况

* 兼容数据为空的情况

* 仅在选中拖拽区域触发快捷操作

* 修改判断是否在拖拽区域

* 增加backspace快速删除
修改快捷面版样式

* 后端采用typeorm

* orm添加migration

* 修改文件名

* 修改数据迁移表

* 1. 新增数据库部署文档
2. 去掉test相关接口
3. 修改initial.sql注释

* 去掉数据迁移部分,采用SQL自己控制

* 1. 修改数据库说明
2. 修改数据库配置注释

* feature: db 操作demo (#235)

* 提交项目模块layout和router & fix高版本echart图表自适应不生效问题 (#236)

* 增加chart图表

* fix冲突

* 删除consolelog

* 更新图标库

* 同步新的lesscode-develop,fix图表bug

* fix高版本echarts无法自适应大小的问题

* project模块layout和router

* 添加函数相关entity (#237)

* 添加快捷操作功能

* 拖拽快捷键支持Mac Command键

* 修改快捷操作说明

* 修复剪切快捷操作,修改快捷操作说明

* 兼容数据为空的情况

* 兼容数据为空的情况

* 仅在选中拖拽区域触发快捷操作

* 修改判断是否在拖拽区域

* 增加backspace快速删除
修改快捷面版样式

* 后端采用typeorm

* orm添加migration

* 修改文件名

* 修改数据迁移表

* 1. 新增数据库部署文档
2. 去掉test相关接口
3. 修改initial.sql注释

* 去掉数据迁移部分,采用SQL自己控制

* 1. 修改数据库说明
2. 修改数据库配置注释

* 1. entity的base 添加创建人和修改人字段
2. 添加函数相关的entities
3. 修改initial.sql

* 修改字段类型

* 新增项目相关功能 (#238)

* 新增项目级别页面布局和项目列表页UI

* 新增创建项目和查询项目列表功能

* 新增项目收藏功能

* 新增项目重命名功能

* 新增项目列表分类和搜索查询

* 新增复制项目功能

* 修改项目收藏功能使用独立的数据接口和模型

* 优化项目列表查询

* 新增删除项目功能

Co-authored-by: ielgnaw <[email protected]>

* 添加权限相关方法 (#240)

* 添加快捷操作功能

* 拖拽快捷键支持Mac Command键

* 修改快捷操作说明

* 修复剪切快捷操作,修改快捷操作说明

* 兼容数据为空的情况

* 兼容数据为空的情况

* 仅在选中拖拽区域触发快捷操作

* 修改判断是否在拖拽区域

* 增加backspace快速删除
修改快捷面版样式

* 后端采用typeorm

* orm添加migration

* 修改文件名

* 修改数据迁移表

* 1. 新增数据库部署文档
2. 去掉test相关接口
3. 修改initial.sql注释

* 去掉数据迁移部分,采用SQL自己控制

* 1. 修改数据库说明
2. 修改数据库配置注释

* 1. entity的base 添加创建人和修改人字段
2. 添加函数相关的entities
3. 修改initial.sql

* 修改字段类型

* 1. 添加权限相关的实体和接口
2. 添加创建人和更新人字段

Co-authored-by: ielgnaw <[email protected]>

* 解决冲突 (#241)

* 添加快捷操作功能

* 拖拽快捷键支持Mac Command键

* 修改快捷操作说明

* 修复剪切快捷操作,修改快捷操作说明

* 兼容数据为空的情况

* 兼容数据为空的情况

* 仅在选中拖拽区域触发快捷操作

* 修改判断是否在拖拽区域

* 增加backspace快速删除
修改快捷面版样式

* 后端采用typeorm

* orm添加migration

* 修改文件名

* 修改数据迁移表

* 1. 新增数据库部署文档
2. 去掉test相关接口
3. 修改initial.sql注释

* 去掉数据迁移部分,采用SQL自己控制

* 1. 修改数据库说明
2. 修改数据库配置注释

* 1. entity的base 添加创建人和修改人字段
2. 添加函数相关的entities
3. 修改initial.sql

* 修改字段类型

* 解决冲突

* 统一实体导入导出与命名规则 (#242)

* 新增项目级别页面布局和项目列表页UI

* 新增创建项目和查询项目列表功能

* 新增项目收藏功能

* 新增项目重命名功能

* 新增项目列表分类和搜索查询

* 新增复制项目功能

* 修改项目收藏功能使用独立的数据接口和模型

* 优化项目列表查询

* 新增删除项目功能

Co-authored-by: ielgnaw <[email protected]>

* 自定义组件接口 (#243)

* feature: db 操作demo

* perf: 组件管理接口联调

* perf: 修改实体引入方式

* fix: 自定义组件上传 (#244)

* feature: db 操作demo

* perf: 组件管理接口联调

* perf: 修改实体引入方式

* fix: 自定义组件上传

Co-authored-by: ielgnaw <[email protected]>

* 函数页面及接口 (#245)

* 添加快捷操作功能

* 拖拽快捷键支持Mac Command键

* 修改快捷操作说明

* 修复剪切快捷操作,修改快捷操作说明

* 兼容数据为空的情况

* 兼容数据为空的情况

* 仅在选中拖拽区域触发快捷操作

* 修改判断是否在拖拽区域

* 增加backspace快速删除
修改快捷面版样式

* 后端采用typeorm

* orm添加migration

* 修改文件名

* 修改数据迁移表

* 1. 新增数据库部署文档
2. 去掉test相关接口
3. 修改initial.sql注释

* 去掉数据迁移部分,采用SQL自己控制

* 1. 修改数据库说明
2. 修改数据库配置注释

* 1. entity的base 添加创建人和修改人字段
2. 添加函数相关的entities
3. 修改initial.sql

* 修改字段类型

* 解决冲突

* 添加函数相关页面及接口

* up data-base conf example

* up data-base conf example (#246)

* 提交页面管理 (#247)

* 提交页面管理

* merge

Co-authored-by: ielgnaw <[email protected]>

* merge page && page 表,content 和 sourceCode 改为允许 null

* merge page && page 表,content 和 sourceCode 改为允许 null (#248)

* fix页面管理问题 (#249)

* fix复制页面问题

* 删除preview页面的query参数

* update msg

Co-authored-by: ielgnaw <[email protected]>

* format code style

* format code style (#250)

* page 模块小问题修复

* page 模块小问题修复 (#251)

* 1. 函数体验优化
2. 函数对接项目

* 修改整体路由、生成页面缩略图 (#253)

* 增加chart图表

* fix冲突

* 删除consolelog

* 更新图标库

* 同步新的lesscode-develop,fix图表bug

* fix高版本echarts无法自适应大小的问题

* project模块layout和router

* 提交页面管理

* merge

* fix复制页面问题

* 删除preview页面的query参数

* update msg

* 修改整体路由、生成页面缩略图

Co-authored-by: ielgnaw <[email protected]>

* 1. 函数体验优化 (#252)

2. 函数对接项目

* 通过手动保存方式串联流程 (#254)

* 修改整体路由、生成页面缩略图

* 增加手动保存串连流程

* 删除consolelog

Co-authored-by: ielgnaw <[email protected]>

* merge

* merge && cookie

* merge && cookie (#255)

* 修改删除和新增分类的项目

* 修改删除和新增分类的项目 (#256)

* 1. 函数体验优化
2. 函数对接项目

* 修改删除和新增分类的项目

* 函数修改为可以选中所有模板生成的函数

* 登录权限控制 & 账号管理页面 & 用户信息

* 登录权限控制 & 账号管理页面 & 用户信息 (#259)

* entities base 中尝试获取 curLoginUser (#260)

* 登录权限控制 & 账号管理页面 & 用户信息

* entities base 中尝试获取 curLoginUser

* fix页面管理体验问题 (#257)

* fix页面管理体验问题

* 下拉项目列表增加搜索

Co-authored-by: ielgnaw <[email protected]>

* 使用函数的时候,可以选择所有模板生成的函数 (#258)

* 1. 函数体验优化
2. 函数对接项目

* 修改删除和新增分类的项目

* 函数修改为可以选中所有模板生成的函数

* add http.js.example

* add http.js.example (#261)

* 项目管理对接登录用户和复制项目及样式与交互优化 (#262)

* 新增项目级别页面布局和项目列表页UI

* 新增创建项目和查询项目列表功能

* 新增项目收藏功能

* 新增项目重命名功能

* 新增项目列表分类和搜索查询

* 新增复制项目功能

* 修改项目收藏功能使用独立的数据接口和模型

* 优化项目列表查询

* 新增删除项目功能

* 项目管理样式和交互优化

* 项目对接登录用户和复制项目优化

Co-authored-by: ielgnaw <[email protected]>

* 处理projectId不存在情况,fix页面管理样式问题 (#263)

* 增加chart图表

* fix冲突

* 删除consolelog

* 更新图标库

* 同步新的lesscode-develop,fix图表bug

* fix高版本echarts无法自适应大小的问题

* project模块layout和router

* 提交页面管理

* merge

* fix复制页面问题

* 删除preview页面的query参数

* update msg

* 修改整体路由、生成页面缩略图

* 增加手动保存串连流程

* 删除consolelog

* fix页面管理体验问题

* 下拉项目列表增加搜索

* 处理projectId不存在情况,fix页面管理样式问题

Co-authored-by: ielgnaw <[email protected]>

* 数据库默认值调整 (#264)

* merge #201

* merge manually from #201

* merge manually from #203

* fix some bug

* 修复 charts-line options.tips 小问题

* 修复刷新页面时,没有选中组件但右侧面板会显示 grid 属性的问题

* 修复 chart 组件样式被覆盖的问题

* 体验 bug 修复

* 修复体验问题

* 画布仅剩一个 grid 时,不允许删除;增加清空 grid 操作

* 修复 clone grid 时,右侧面板没有默认选中的问题;更新日志

* 文案

* up data-base conf example

* merge page && page 表,content 和 sourceCode 改为允许 null

* format code style

* page 模块小问题修复

* merge

* merge && cookie

* 登录权限控制 & 账号管理页面 & 用户信息

* add http.js.example

* 修复自定义组件 x-table 获取数据的问题

* 统一操作用户

* 修复自定义组件 x-table 获取数据的问题 (#265)

* 统一操作用户 (#266)

* 1. 函数体验优化
2. 函数对接项目

* 修改删除和新增分类的项目

* 函数修改为可以选中所有模板生成的函数

* 统一操作用户

* 获取正确的当前登录用户写入数据库 createUser 和 updateUser

* 获取正确的当前登录用户写入数据库 createUser 和 updateUser (#267)

* 修复 cookie 中 bktoken 失效的问题

* 项目复制完善和项目列表体验问题修复 (#268)

* 项目列表体验优化

Co-authored-by: ielgnaw <[email protected]>

* 修复 cookie 中 bktoken 失效的问题 (#269)

* 函数体验优化

* 去除重复js

* fix页面管理相关体验问题 (#271)

* 处理projectId不存在情况,fix页面管理样式问题

* 页面管理体验问题修复

* fix page style

Co-authored-by: ielgnaw <[email protected]>

* 函数体验问题修复 (#270)

* 1. 函数体验优化
2. 函数对接项目

* 修改删除和新增分类的项目

* 函数修改为可以选中所有模板生成的函数

* 统一操作用户

* 函数体验优化

* 去除重复js

* 函数api url提示,默认函数填写绝对路径

* 去掉多余的空格

* 函数体验问题修复 (#272)

* 1. 函数体验优化
2. 函数对接项目

* 修改删除和新增分类的项目

* 函数修改为可以选中所有模板生成的函数

* 统一操作用户

* 函数体验优化

* 去除重复js

* 函数api url提示,默认函数填写绝对路径

* 去掉多余的空格

* 修改layout样式

* 导航与主站一致

* 导航与主站一致 (#274)

* 导航与主站一致

* 导航与主站一致

* 隐藏项目删除操作和画布内容区加loading等体验问题修复 (#275)

* 新增项目级别页面布局和项目列表页UI

* 新增创建项目和查询项目列表功能

* 新增项目收藏功能

* 新增项目重命名功能

* 新增项目列表分类和搜索查询

* 新增复制项目功能

* 修改项目收藏功能使用独立的数据接口和模型

* 优化项目列表查询

* 新增删除项目功能

* 项目管理样式和交互优化

* 项目对接登录用户和复制项目优化

* 复制项目补充页面函数关联记录

* 项目列表体验优化

* 体验问题修复

Co-authored-by: ielgnaw <[email protected]>

* 修复属性面板中 switch 组件不会正确渲染的问题

* 修复属性面板中 switch 组件不会正确渲染的问题 (#276)

* 函数提示优化,增加按钮获取数据 (#277)

* 项目名称、ID 校验去重在当前用户维度下

* 项目名称、ID 校验去重在当前用户维度下 (#278)

* 修复 compId 的问题

* 修复 compId 的问题 (#280)

Co-authored-by: hLinx <[email protected]>
Co-authored-by: sundytt <[email protected]>
Co-authored-by: Arman19941113 <[email protected]>
Co-authored-by: xuzhan <[email protected]>
Co-authored-by: terlinhe <[email protected]>
Co-authored-by: yangyy <[email protected]>
  • Loading branch information
7 people authored Aug 14, 2020
1 parent ae6425f commit 24ee127
Show file tree
Hide file tree
Showing 111 changed files with 9,059 additions and 1,623 deletions.
2 changes: 2 additions & 0 deletions paas-ce/lesscode/.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"lodash",
"@babel/plugin-syntax-dynamic-import",
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose" : true }],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
Expand All @@ -32,6 +33,7 @@
"plugins": [
"istanbul",
["@babel/plugin-proposal-decorators", { "legacy": true }],
["@babel/plugin-proposal-class-properties", { "loose" : true }],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
Expand Down
8 changes: 6 additions & 2 deletions paas-ce/lesscode/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
sourceType: 'module'
sourceType: 'module',
ecmaFeatures: {
legacyDecorators: true
}
},
env: {
browser: true
Expand All @@ -23,7 +26,8 @@ module.exports = {
APP_CODE: false,
ENV: false,
monaco: false,
ResizeSensor: false
ResizeSensor: false,
define: false
},
// add your custom rules hered
rules: {
Expand Down
2 changes: 2 additions & 0 deletions paas-ce/lesscode/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ lib/client/static/lib-manifest.json
lib/client/static/lib.bundle.js
lib/client/static/vue-layout-demo*.vue
!lib/client/static/ResizeSensor.js
lib/server/conf/data-base.js
lib/server/conf/http.js
1 change: 1 addition & 0 deletions paas-ce/lesscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
## 安装部署
- [本地开发部署](./docs/install/dev_install.md)
- [生产环境部署](./docs/install/prod_install.md)
- [数据库说明](./docs/install/database.md)

## 开发文档
- [自定义组件开发文档](./docs/develop/dev_com.md)
Expand Down
17 changes: 17 additions & 0 deletions paas-ce/lesscode/docs/install/database.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# 蓝鲸智云PaaS平台社区版之可视化开发平台

## 数据库说明

需要用户自己提供 MySQL 服务并做 db 授权。本地开发和生产环境的数据库初始化和变更流程是一样的,都需要自己执行SQL对数据库进行修改。执行 SQL 分两种,初始化时执行的 SQL 和升级时执行的 SQL。SQL 文件存放于 `lesscode/lib/server/model/sql` 文件夹下。

## 数据库配置说明

在本地开发和生产环境中,需要依照 [数据库配置示例](../../lib/server/conf/data-base.js.example)`lesscode/lib/server/conf` 中新建 `data-base.js` 文件(复制 `data-base.js.example`,并删除 `.example`即可)。然后依照 `data-base.js.example` 的注释填写数据库的配置信息。

## 数据库初始化说明

`lesscode/lib/server/model/sql` 文件夹下,每次发版都会新建一个文件夹,以发布日期命名,里面的 `initial.sql` 为安装该版本需要的所有 SQL,包含了建表语句和初始化数据。初次安装的时候,需要手动执行该SQL,即完成了数据库初始化。注意:如果不是数据库初始化,执行该 SQL 会导致数据丢失。如果是升级,请按照数据库表结构变更来操作。

## 数据库表结构变更说明

`lesscode/lib/server/model/sql` 文件夹下,每次发布还会生成 `update.sql``update.sql` 是从上一个版本升级到这个版本的 SQL 语句,包含了修改表结构语句和初始化数据。如果这次升级数据库,跨越了3个版本,那么这3个版本的 `update.sql` 需要按照版本顺序都执行一次,即完成了数据库表结构变更。
4 changes: 2 additions & 2 deletions paas-ce/lesscode/lib/client/build/webpack.base.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ module.exports = {
resolve(__dirname, '..', 'src'),
resolve(__dirname, '../../../node_modules', 'bk-magic-vue'),
resolve(__dirname, '../../../node_modules', 'monaco-editor'),
resolve(__dirname, '../../../node_modules', 'vue-echarts'),
resolve(__dirname, '../../../node_modules', 'resize-detector')
resolve(__dirname, '../../../node_modules', 'vue-echarts')
// resolve(__dirname, '../../../node_modules', 'resize-detector')
],
cacheDirectory: resolve(__dirname, '..', '.webpack_cache'),
presets: [
Expand Down
9 changes: 7 additions & 2 deletions paas-ce/lesscode/lib/client/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
</transition>
</div>
</section>

</template>
<script>
import { mapGetters } from 'vuex'
import { bus } from './common/bus'
export default {
name: 'app',
Expand All @@ -42,17 +43,21 @@
}
},
created () {
mounted () {
const platform = window.navigator.platform.toLowerCase()
if (platform.indexOf('win') === 0) {
this.systemCls = 'win'
}
bus.$on('redirect-login', data => {
window.location.replace(data.loginUrl)
})
}
}
</script>

<style lang="postcss">
@import './css/reset.css';
@import './css/common.css';
@import './css/bk-patch.css';
@import "@/css/mixins/scroller";
Expand Down
10 changes: 4 additions & 6 deletions paas-ce/lesscode/lib/client/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* specific language governing permissions and limitations under the License.
*/

import Vue from 'vue'
import axios from 'axios'
import cookie from 'cookie'

Expand Down Expand Up @@ -136,7 +135,7 @@ async function getPromise (method, url, data, userConfig = {}) {
* @param {Function} promise 拒绝函数
*/
function handleResponse ({ config, response, resolve, reject }) {
if (!response.data && config.globalError) {
if (response.code !== 0 && config.globalError) {
reject({ message: response.message })
} else {
resolve(config.originalResponse ? response : response.data, config)
Expand All @@ -163,13 +162,14 @@ function handleReject (error, config) {
const { status, data } = error.response
const nextError = { message: error.message, response: error.response }
if (status === 401) {
bus.$emit('show-login-modal')
bus.$emit('redirect-login', nextError.response.data.data || {})
} else if (data && data.message) {
nextError.message = data.message
messageError(nextError.message)
} else if (status === 500) {
nextError.message = '服务器内部出错'
messageError(nextError.message)
}
messageError(nextError.message)
console.error(nextError.message)
return Promise.reject(nextError)
}
Expand Down Expand Up @@ -224,8 +224,6 @@ function getCancelToken () {
}
}

Vue.prototype.$http = http

export default http

// 跨域处理
Expand Down
207 changes: 207 additions & 0 deletions paas-ce/lesscode/lib/client/src/api/pureAxios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
/**
* Tencent is pleased to support the open source community by making 蓝鲸智云PaaS平台社区版 (BlueKing PaaS Community Edition) available.
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://opensource.org/licenses/MIT
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

import axios from 'axios'

import CachedPromise from './cached-promise'
import RequestQueue from './request-queue'
import { messageError } from '@/common/bkmagic'

// axios 实例
const axiosInstance = axios.create({
xsrfCookieName: 'bkiam_csrftoken',
xsrfHeaderName: 'X-CSRFToken',
withCredentials: true,
baseURL: `${AJAX_URL_PREFIX}`
})

/**
* response interceptor
*/
axiosInstance.interceptors.response.use(
response => response.data,
error => Promise.reject(error)
)

const http = {
queue: new RequestQueue(),
cache: new CachedPromise(),
cancelRequest: requestId => {
return http.queue.cancel(requestId)
},
cancelCache: requestId => http.cache.delete(requestId),
cancel: requestId => Promise.all([http.cancelRequest(requestId), http.cancelCache(requestId)])
}

const methodsWithoutData = ['delete', 'get', 'head', 'options', 'connect', 'trace']
const methodsWithData = ['post', 'put', 'patch']
const allMethods = [...methodsWithoutData, ...methodsWithData]

// 在自定义对象 http 上添加各请求方法
allMethods.forEach(method => {
Object.defineProperty(http, method, {
get () {
return getRequest(method)
}
// get: () => getRequest(method)
})
})

/**
* 获取 http 不同请求方式对应的函数
*
* @param {string} http method axios 实例中的 method 保持一致
*
* @return {Function} 实际调用的请求函数
*/
function getRequest (method) {
if (methodsWithData.includes(method)) {
return (url, data, config) => getPromise(method, url, data, config)
}
return (url, config) => getPromise(method, url, null, config)
}

/**
* 实际发起 http 请求的函数根据配置调用缓存的 promise 或者发起新的请求
*
* @param {method} http method axios 实例中的 method 保持一致
* @param {string} 请求地址
* @param {Object} 需要传递的数据, post/put/patch 三种请求方式可用
* @param {Object} 用户配置包含 axios 的配置与本系统自定义配置
*
* @return {Promise} 本次http请求的Promise
*/
async function getPromise (method, url, data, userConfig = {}) {
const config = initConfig(method, url, userConfig)
let promise
if (config.cancelPrevious) {
await http.cancel(config.requestId)
}

if (config.clearCache) {
http.cache.delete(config.requestId)
} else {
promise = http.cache.get(config.requestId)
}

if (config.fromCache && promise) {
return promise
}

// eslint-disable-next-line no-async-promise-executor
promise = new Promise(async (resolve, reject) => {
const axiosRequest = methodsWithData.includes(method)
? axiosInstance[method](url, data, config)
: axiosInstance[method](url, config)

try {
const response = await axiosRequest
Object.assign(config, response.config || {})
handleResponse({ config, response, resolve, reject })
} catch (error) {
Object.assign(config, error.config)
reject(error)
}
}).catch(error => {
return handleReject(error, config)
}).finally(() => {
// console.log('finally', config)
})

// 添加请求队列
http.queue.set(config)
// 添加请求缓存
http.cache.set(config.requestId, promise)

return promise
}

/**
* 处理 http 请求成功结果
*
* @param {Object} 请求配置
* @param {Object} cgi 原始返回数据
* @param {Function} promise 完成函数
* @param {Function} promise 拒绝函数
*/
function handleResponse ({ config, response, resolve }) {
resolve(response, config)
http.queue.delete(config.requestId)
}

/**
* 处理 http 请求失败结果
*
* @param {Object} Error 对象
* @param {config} 请求配置
*
* @return {Promise} promise 对象
*/
function handleReject (error, config) {
if (axios.isCancel(error)) {
return Promise.reject(error)
}

http.queue.delete(config.requestId)
let errMessage = error.message || error
if (typeof errMessage === 'string' && errMessage.match(/Network Error/)) errMessage = 'Network Error,网络不可用,有可能是跨域原因引起'
messageError(errMessage)
console.error(error)
return Promise.reject(error)
}

/**
* 初始化本系统 http 请求的各项配置
*
* @param {string} http method axios 实例中的 method 保持一致
* @param {string} 请求地址, 结合 method 生成 requestId
* @param {Object} 用户配置包含 axios 的配置与本系统自定义配置
*
* @return {Promise} 本次 http 请求的 Promise
*/
function initConfig (method, url, userConfig) {
const defaultConfig = {
...getCancelToken(),
// http 请求默认 id
requestId: method + '_' + url,
// 是否全局捕获异常
globalError: true,
// 是否直接复用缓存的请求
fromCache: false,
// 是否在请求发起前清楚缓存
clearCache: false,
// 响应结果是否返回原始数据
originalResponse: true,
// 当路由变更时取消请求
cancelWhenRouteChange: true,
// 取消上次请求
cancelPrevious: true
}
return Object.assign(defaultConfig, userConfig)
}

/**
* 生成 http 请求的 cancelToken用于取消尚未完成的请求
*
* @return {Object} {cancelToken: axios 实例使用的 cancelToken, cancelExcutor: 取消http请求的可执行函数}
*/
function getCancelToken () {
let cancelExcutor
const cancelToken = new axios.CancelToken(excutor => {
cancelExcutor = excutor
})
return {
cancelToken,
cancelExcutor
}
}

export default http
4 changes: 2 additions & 2 deletions paas-ce/lesscode/lib/client/src/common/bkmagic.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import Vue from 'vue'

// 全量引入
// import './fully-import'
import './fully-import'

// 按需引入
import './demand-import'
// import './demand-import'

const Message = Vue.prototype.$bkMessage

Expand Down
7 changes: 7 additions & 0 deletions paas-ce/lesscode/lib/client/src/common/fully-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@

import Vue from 'vue'
import bkMagicVue from 'bk-magic-vue'
import bkText from '@/components/patch/text'
import bkImage from '@/components/patch/image'
import chart from '@/components/patch/chart'

Vue.use(bkText)
Vue.use(bkImage)
Vue.use(chart)
Vue.use(bkMagicVue)
Loading

0 comments on commit 24ee127

Please sign in to comment.