Skip to content

Commit

Permalink
Merge pull request #9 from HammCn/dev
Browse files Browse the repository at this point in the history
release(v2.3.3): 发布了`v2.3.3`版本
  • Loading branch information
HammCn authored Aug 31, 2024
2 parents c8bfbd6 + e7259d7 commit 388dae5
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 70 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# AirPower4T 版本发布日志


## v2.3.3

### 🎉 Features:

- feat(Service): 新增可选的自定义请求URL参数

### 🐞 Bug fixes:

- fix(DateTime): 移除DateTime组件中不必要的CSS规则
- fix(Dialog): 优化Dialog组件字体和按钮的CSS
- fix(AirModel): 移除AirModel内处理'Sass.types'的代码行
- fix(DateTime): 优化`AirDateTime`中时间戳和日期格式化的逻辑
- fix(Group): 只有一列时自动方向改为纵向且支持最小高度

## v2.3.2

### 🎉 Features:
Expand Down
45 changes: 27 additions & 18 deletions base/AirAbstractEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ export abstract class AirAbstractEntityService<E extends AirEntity> extends AirA
/**
* ## 查询分页数据列表
* @param request 请求对象
* @param apiUrl `可选` 自定义请求URL
*/
async getPage(request: AirRequest<E>): Promise<AirResponsePage<E>> {
const json = await this.api(this.urlForGetPage)
async getPage(request: AirRequest<E>, apiUrl = this.urlForGetPage): Promise<AirResponsePage<E>> {
const json = await this.api(apiUrl)
.post(request)
const responsePage = AirClassTransformer.parse<AirResponsePage<E>>(json, AirResponsePage)
responsePage.list = AirClassTransformer.parseArray(responsePage.list as IJson[], this.entityClass)
Expand All @@ -84,29 +85,32 @@ export abstract class AirAbstractEntityService<E extends AirEntity> extends AirA
/**
* ## 查询不分页数据列表
* @param request 请求对象
* @param apiUrl `可选` 自定义请求URL
*/
async getList(request: AirRequest<E>): Promise<E[]> {
const json = await this.api(this.urlForGetList)
async getList(request: AirRequest<E>, apiUrl = this.urlForGetList): Promise<E[]> {
const json = await this.api(apiUrl)
.post(request) as IJson[]
return AirClassTransformer.parseArray(json, this.entityClass)
}

/**
* ## 查询树结构数据数组
* @param request 请求对象
* @param apiUrl `可选` 自定义请求URL
*/
async getTreeList(request: AirRequest<E>): Promise<E[]> {
const json = await this.api(this.urlForGetTreeList)
async getTreeList(request: AirRequest<E>, apiUrl = this.urlForGetTreeList): Promise<E[]> {
const json = await this.api(apiUrl)
.post(request) as IJson[]
return AirClassTransformer.parseArray(json, this.entityClass)
}

/**
* ## 根据 `ID` 获取详情对象
* @param id ID
* @param apiUrl `可选` 自定义请求URL
*/
async getDetail(id: number): Promise<E> {
const json = await this.api(this.urlForGetDetail)
async getDetail(id: number, apiUrl = this.urlForGetDetail): Promise<E> {
const json = await this.api(apiUrl)
.post(this.newEntityInstance(id))
return AirClassTransformer.parse(json, this.entityClass)
}
Expand All @@ -116,9 +120,10 @@ export abstract class AirAbstractEntityService<E extends AirEntity> extends AirA
* @param data 保存的数据
* @param message `可选` 添加成功的消息提示内容
* @param title `可选` 添加成功的消息提示标题 默认 `添加成功`
* @param apiUrl `可选` 自定义请求URL
*/
async add(data: E, message?: string, title = '添加成功'): Promise<number> {
const json = await this.api(this.urlForAdd)
async add(data: E, message?: string, title = '添加成功', apiUrl = this.urlForAdd): Promise<number> {
const json = await this.api(apiUrl)
.post(data)
if (message) {
AirNotification.success(message, title)
Expand All @@ -131,9 +136,10 @@ export abstract class AirAbstractEntityService<E extends AirEntity> extends AirA
* @param data 修改的数据实体
* @param message `可选` 修改成功的消息提示内容
* @param title `可选` 修改成功的消息提示标题 默认 `修改成功`
* @param apiUrl `可选` 自定义请求URL
*/
async update(data: E, message?: string, title = '修改成功'): Promise<void> {
await this.api(this.urlForUpdate)
async update(data: E, message?: string, title = '修改成功', apiUrl = this.urlForUpdate): Promise<void> {
await this.api(apiUrl)
.post(data)
if (message) {
AirNotification.success(message, title)
Expand Down Expand Up @@ -161,10 +167,11 @@ export abstract class AirAbstractEntityService<E extends AirEntity> extends AirA
* @param id 删除的数据 `ID`
* @param message `可选` 删除成功的消息提示内容
* @param title `可选` 删除成功的消息提示标题 默认 `删除成功`
* @param apiUrl `可选` 自定义请求URL
*/
async delete(id: number, message?: string, title = '删除成功'): Promise<void> {
async delete(id: number, message?: string, title = '删除成功', apiUrl = this.urlForDelete): Promise<void> {
try {
await this.api(this.urlForDelete)
await this.api(apiUrl)
.callbackError()
.post(this.newEntityInstance(id))
if (message) {
Expand All @@ -180,10 +187,11 @@ export abstract class AirAbstractEntityService<E extends AirEntity> extends AirA
* @param id 禁用的数据 `ID`
* @param message `可选` 禁用成功的消息提示内容
* @param title `可选` 禁用成功的消息提示标题 默认 `禁用成功`
* @param apiUrl `可选` 自定义请求URL
*/
async disable(id: number, message?: string, title = '禁用成功'): Promise<void> {
async disable(id: number, message?: string, title = '禁用成功', apiUrl = this.urlForDisable): Promise<void> {
try {
await this.api(this.urlForDisable)
await this.api(apiUrl)
.callbackError()
.post(this.newEntityInstance(id))
if (message) {
Expand All @@ -199,10 +207,11 @@ export abstract class AirAbstractEntityService<E extends AirEntity> extends AirA
* @param id 启用的数据 `ID`
* @param message `可选` 启用成功的消息提示内容
* @param title `可选` 启用成功的消息提示标题 默认 `启用成功`
* @param apiUrl `可选` 自定义请求URL
*/
async enable(id: number, message?: string, title = '启用成功'): Promise<void> {
async enable(id: number, message?: string, title = '启用成功', apiUrl = this.urlForEnable): Promise<void> {
try {
await this.api(this.urlForEnable)
await this.api(apiUrl)
.callbackError()
.post(this.newEntityInstance(id))
if (message) {
Expand Down
4 changes: 1 addition & 3 deletions base/AirEntity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
Dictionary, Field, Type,
} from '../decorator/Custom'
import { Dictionary, Field, Type } from '../decorator/Custom'
import { AirModel } from './AirModel'
import { Table } from '../decorator/TableField'
import { AirDisableDictionary } from '../model/AirDisableDictionary'
Expand Down
3 changes: 0 additions & 3 deletions base/AirModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,13 @@ export class AirModel {
continue
}
switch (FieldTypeClass.name) {
case 'sass.types.String':
case 'String':
(instance as IJson)[fieldKey] = fieldData.toString()
break
case 'sass.types.Number':
case 'Number':
// 强制转换为Number, 但如果不是标准的Number, 则忽略掉值
(instance as IJson)[fieldKey] = (Number.isNaN(parseFloat(fieldData)) ? undefined : parseFloat(fieldData))
break
case 'sass.types.Boolean':
case 'Boolean':
// 强制转换为布尔型
(instance as IJson)[fieldKey] = !!fieldData
Expand Down
7 changes: 1 addition & 6 deletions component/DateTime.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,10 @@ const toolTips = computed(() => {
}
return AirDateTime.formatFromMilliSecond(props.time, props.formatter)
})
</script>
<style lang="scss">
<style lang="scss" scoped>
.air-friend-datetime,
.air-friend-datetime * {
user-select: none !important;
.is-disabled {
color: #333;
}
}
</style>
3 changes: 1 addition & 2 deletions component/Dialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ async function confirmEvent() {
.title {
font-weight: normal;
flex: 1;
font-weight: 16px;
}
.airpower {
Expand Down Expand Up @@ -575,7 +574,7 @@ async function confirmEvent() {
display: flex;
flex-direction: row;
.el-button {
::v-deep(.el-button) {
padding: 6px 30px;
margin-left: 15px;
}
Expand Down
11 changes: 10 additions & 1 deletion component/Group.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
v-show="!isCollapse"
:class="getBodyClass()"
class="group-body"
:style="{ paddingTop: hideTitle ? '0' : '10px' }"
:style="{ paddingTop: hideTitle ? '0' : '10px', minHeight: minHeight || 'auto', flexDirection: column === 1 ? 'column' : 'row' }"
>
<slot />
</div>
Expand All @@ -42,6 +42,14 @@ import { ref } from 'vue'
import { ArrowDown, ArrowRight } from '@element-plus/icons-vue'
const props = defineProps({
/**
* ## 最低高度
*/
minHeight: {
type: String,
default: undefined,
},
/**
* # 隐藏标题
*/
Expand Down Expand Up @@ -132,6 +140,7 @@ function getBodyClass() {
flex-direction: row;
flex-wrap: wrap;
display: flex;
position: relative;
.el-cascader,
.el-select {
Expand Down
15 changes: 13 additions & 2 deletions component/Tab.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
<template>
<el-tab-pane class="air-tab">
<el-tab-pane
class="air-tab"
:label="label"
>
<slot />
</el-tab-pane>
</template>
<script setup lang="ts">
defineProps({
/**
* ## Tab标题
*/
label: {
type: String,
default: 'Tab',
},
})
</script>
<style lang="scss" scoped></style>
11 changes: 3 additions & 8 deletions component/Tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@
</el-tabs>
</template>
<script setup lang="ts">
</script>
<style lang="scss" scoped>
.air-tabs {
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
display: flex;
flex-direction: column;
min-height: 100px;
flex: 1;
height: 0;
::v-deep(.el-tabs__content) {
display: flex;
Expand Down
2 changes: 1 addition & 1 deletion config/AirConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class AirConfig {
/**
* ## `AirPower` 版本号
*/
static readonly version = 'v2.3.2'
static readonly version = 'v2.3.3'

/**
* ## `AppKey`
Expand Down
27 changes: 6 additions & 21 deletions helper/AirDateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,12 @@ export class AirDateTime {
*/
static getMilliTimeStamps(date?: Date | string): number {
if (!date) {
date = new Date()
return new Date().valueOf()
}
switch (typeof date) {
case 'string':
return new Date(date).valueOf()
case 'object':
if (date instanceof Date) {
return date.valueOf()
}
break
default:
if (typeof data === 'object') {
return date.valueOf()
}
return 0
return new Date(date).valueOf()
}

/**
Expand Down Expand Up @@ -76,16 +69,8 @@ export class AirDateTime {
if (!formatString) {
formatString = AirConfig.dateTimeFormatter
}
switch (typeof date) {
case 'string':
date = new Date(date)
break
case 'object':
if (!(date instanceof Date)) {
date = new Date()
}
break
default:
if (typeof date !== 'object') {
date = new Date(date)
}
const dict: IJson = {
YYYY: date.getFullYear(),
Expand Down
6 changes: 3 additions & 3 deletions hook/airTableHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export function airTableHook<E extends AirEntity, S extends AirAbstractEntitySer
}
}
if (option.treeList) {
list.value = await service.getTreeList(req)
list.value = await service.getTreeList(req, option.apiUrl)
} else if (!option.unPaginate) {
response.value = await service.getPage(req)
response.value = await service.getPage(req, option.apiUrl)
list.value = response.value.list
} else {
list.value = await service.getList(req)
list.value = await service.getList(req, option.apiUrl)
}
}

Expand Down
2 changes: 1 addition & 1 deletion hook/useAirDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function useAirDetail<E extends AirEntity, S extends AirAbstractEntitySer
*/
async function getDetail() {
if (formData.value.id) {
formData.value = await service.getDetail(formData.value.id)
formData.value = await service.getDetail(formData.value.id, option.apiUrl)

if (option.afterGetDetail) {
const result = option.afterGetDetail(formData.value)
Expand Down
7 changes: 6 additions & 1 deletion hook/useAirEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ export function useAirEditor<E extends AirEntity, S extends AirAbstractEntitySer
postData = result
}
try {
const id = await result.service.save(postData, option.successMessage || (postData.id ? (AirI18n.get().EditSuccess || '编辑成功') : (AirI18n.get().AddSuccess || '添加成功')))
if (postData.id) {
const id = await result.service.update(postData, option.successMessage || (AirI18n.get().EditSuccess || '编辑成功'), option.apiUrlUpdate)
props.onConfirm(id)
return
}
const id = await result.service.add(postData, option.successMessage || (AirI18n.get().AddSuccess || '添加成功'), option.apiUrlAdd)
props.onConfirm(id)
} catch (e: unknown) {
if ((e as IJson).code === AirConfig.continueCode) {
Expand Down
7 changes: 7 additions & 0 deletions interface/hooks/ITableHookOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ export interface ITableHookOption<E extends AirEntity> {
*/
editView?: Component

/**
* ## 请求的URL
*
* 如不传入,则默认为 `Service` 的 `urlForGetXXX`
*/
apiUrl?: string

/**
* ## 搜索前的拦截方法
* 参数为发起请求的数据,请处理后返回
Expand Down
7 changes: 7 additions & 0 deletions interface/hooks/IUseDetailOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ export interface IUseDetailOption<E extends AirEntity> {
*/
// eslint-disable-next-line no-unused-vars
afterGetDetail?: (detailData: E) => E | void

/**
* ## 请求查询详情的URL
*
* 如不传入,则默认为 `Service` 的 `urlForGetDetail`
*/
apiUrl?: string
}
Loading

0 comments on commit 388dae5

Please sign in to comment.