Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.

Commit

Permalink
chore: camcalcaseKeys
Browse files Browse the repository at this point in the history
  • Loading branch information
Innei committed May 16, 2021
1 parent 3e597d2 commit 50697e5
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 55 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"@fortawesome/vue-fontawesome": "2.0.2",
"@types/inflection": "1.5.28",
"axios": "0.21.1",
"core-js": "3.12.0",
"camelcase-keys": "6.2.2",
"core-js": "3.10.2",
"dayjs": "1.10.4",
"element-ui": "2.13.0",
"inflection": "1.13.1",
Expand Down
4 changes: 2 additions & 2 deletions src/api/rest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export const rest = (rest: keyof typeof AccessRoutesEnum, prefix?: string) => {
})
return data as any
},
async getOne<T = any>(_id = '', config?: AxiosRequestConfig): Promise<T> {
const id = encodeURI(_id)
async getOne<T = any>(id = '', config?: AxiosRequestConfig): Promise<T> {
id = encodeURI(id)
const data = await $axios.get(`${pluralize}${id ? '/' + id : ''}`, config)
return data as any
},
Expand Down
4 changes: 2 additions & 2 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface CommentDto {
}

export interface ProjectDto {
_id?: string
id?: string
name: string
previewUrl?: string
docUrl?: string
Expand All @@ -62,7 +62,7 @@ export interface ProjectDto {
text: string
}
export interface SayDto {
_id?: string
id?: string
text: string
source?: string
author?: string
Expand Down
16 changes: 8 additions & 8 deletions src/models/response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface BaseResp {
interface BaseModel {
created?: string
modified?: string
_id?: string
id?: string
}
export interface LoginRespDto {
ok: number
Expand All @@ -31,7 +31,7 @@ export enum CategoryType {
export interface CategoryRespDto {
type: CategoryType
count: number
_id: string
id: string
created: string
slug: string
name: string
Expand All @@ -45,7 +45,7 @@ export interface PostRespDto extends BaseResp {
data: {
hide: boolean
commentsIndex: number
_id: string
id: string
created: string
modified: string
title: string
Expand All @@ -71,7 +71,7 @@ export interface PagerDto {
}

export interface NoteRecord {
_id: string
id: string
hide: boolean
count: {
read: number
Expand Down Expand Up @@ -106,7 +106,7 @@ export interface CommentModel {
state: number
children: CommentModel[]
commentsIndex: number
_id: string
id: string
author: string
text: string
mail: string
Expand Down Expand Up @@ -138,7 +138,7 @@ export interface SayRespDto extends BaseResp {
export interface PageModel {
commentsIndex: number
order: number
_id: string
id: string
created: Date
modified: Date
title: string
Expand Down Expand Up @@ -167,7 +167,7 @@ export interface LinkRespDto extends BaseResp {
}

export interface MasterModel {
_id: string
id: string
introduce: string
mail: string
url: string
Expand Down Expand Up @@ -207,7 +207,7 @@ export declare namespace UA {
os?: Os
}
export interface Root {
_id: string
id: string
ip?: string
ua: Ua
timestamp: Date
Expand Down
2 changes: 1 addition & 1 deletion src/store/interfaces/category.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CategoryType } from '../../models/response.dto'
export interface CategoryModel {
type: CategoryType
count: number
_id: string
id: string
created: Date
modified: Date
slug: string
Expand Down
2 changes: 1 addition & 1 deletion src/store/modules/category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class CategoryModule extends VuexModule {
created: new Date(category.created),
modified: new Date(category.modified),
}
map.set(category._id, value)
map.set(category.id, value)
})

return map
Expand Down
3 changes: 2 additions & 1 deletion src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import router from '@/router'
import store from '@/store'
import { getToken } from '@/utils/auth'
import axios from 'axios'
import camelcaseKeys from 'camelcase-keys'

const service = axios.create({
baseURL: process.env.VUE_APP_BASE_API || 'http://localhost:2333',
Expand All @@ -36,7 +37,7 @@ service.interceptors.request.use(

service.interceptors.response.use(
(response) => {
const res = response.data
const res = camelcaseKeys(response.data, { deep: true })

return res
},
Expand Down
14 changes: 7 additions & 7 deletions src/views/CommentList/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<router-link
:to="{
name: `edit-${scope.row.refType.toLowerCase()}s`,
query: { id: scope.row.ref && scope.row.ref._id },
query: { id: scope.row.ref && scope.row.ref.id },
}"
class="title"
>{{ scope.row.ref && scope.row.ref.title }}</router-link
Expand All @@ -91,26 +91,26 @@
{{ scope.row.parent.text }}
</blockquote>
<div class="actions">
<span class="action green" @click="changeState(scope.row._id, 1)"
<span class="action green" @click="changeState(scope.row.id, 1)"
>已读</span
>
<span class="action yellow" @click="changeState(scope.row._id, 2)"
<span class="action yellow" @click="changeState(scope.row.id, 2)"
>垃圾</span
>
<span
class="action"
v-if="activeName !== '2'"
@click="
replyDialogVisible = true
replyCid = scope.row._id
replyCid = scope.row.id
"
>
回复
</span>

<el-popconfirm
title="确定删除吗?"
@onConfirm="handleDelete(scope.row._id)"
@onConfirm="handleDelete(scope.row.id)"
>
<span slot="reference" class="action red">删除</span>
</el-popconfirm>
Expand Down Expand Up @@ -224,7 +224,7 @@ export default class CommentList extends Vue {
}
get replyContext() {
return this.comments.find((item) => item._id === this.replyCid) || {}
return this.comments.find((item) => item.id === this.replyCid) || {}
}
async created() {
Expand Down Expand Up @@ -264,7 +264,7 @@ export default class CommentList extends Vue {
}
}
handleSelectionChange(val: CommentModel[]) {
this.multipleSelection = val.map((c) => c._id)
this.multipleSelection = val.map((c) => c.id)
}
fromNow(date: string) {
return relativeTimeFromNow(date)
Expand Down
8 changes: 4 additions & 4 deletions src/views/ManageNote/ListNotes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<template slot-scope="scope">
<el-button
@click.native.prevent="
$router.push('/notes/edit?id=' + data[scope.$index]._id)
$router.push('/notes/edit?id=' + data[scope.$index].id)
"
type="text"
size="small"
Expand Down Expand Up @@ -115,16 +115,16 @@ export default class ListNotes extends Vue {
}
async handleDelete(index: number) {
const _id = this.data[index]._id
await this.$api('Note').delete(_id)
const id = this.data[index].id
await this.$api('Note').delete(id)
this.$notice.success('删除成功')
this.getData()
}
handleEdit(row: NoteRecord) {
this.$router.push({
name: 'edit-notes',
query: {
id: row._id,
id: row.id,
},
})
}
Expand Down
8 changes: 4 additions & 4 deletions src/views/ManagePost/EditPost.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
v-for="(value, key) in categoryRecord"
:key="key"
:label="value.name"
:value="value._id"
:value="value.id"
>
</el-option>
</el-select>
Expand Down Expand Up @@ -161,7 +161,7 @@ export default class PostWriteView extends Mixins(BaseWriter) {
const model: PostDto = {
...this.model,
slug: this.slug,
categoryId: this.category._id,
categoryId: this.category.id,
summary: this.summary === '' ? undefined : this.summary,
hide: this.hide,
copyright: this.copyright,
Expand All @@ -188,7 +188,7 @@ export default class PostWriteView extends Mixins(BaseWriter) {
name: '',
}
return {
_id: this.categoryId,
id: this.categoryId,
slug: category.slug,
name: category.name,
}
Expand All @@ -204,7 +204,7 @@ export default class PostWriteView extends Mixins(BaseWriter) {
if (!defaultCategory) {
return false
}
this.categoryId = defaultCategory._id
this.categoryId = defaultCategory.id
return true
}
Expand Down
12 changes: 6 additions & 6 deletions src/views/ManagePost/ListPosts.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<template slot-scope="scope">
<el-button
@click.native.prevent="
$router.push('/posts/edit?id=' + data[scope.$index]._id)
$router.push('/posts/edit?id=' + data[scope.$index].id)
"
type="text"
size="small"
Expand Down Expand Up @@ -138,16 +138,16 @@ export default {
return this.categories.get(id)?.name
},
async handleDelete(index) {
const _id = this.data[index]._id
await this.$api('Post').delete(_id)
const id = this.data[index].id
await this.$api('Post').delete(id)
this.$notice.success('删除成功')
this.getData()
},
handleEdit(row) {
this.$router.push({
name: 'edit-posts',
query: {
id: row._id,
id: row.id,
},
})
},
Expand Down Expand Up @@ -205,9 +205,9 @@ export default {
data = data
.map((c) => {
return c.category.children.map((ch) => ({
...omit(c.category, ['children', 'id', '_id']),
...omit(c.category, ['children', 'id', 'id']),
...ch,
categoryId: c.category._id,
categoryId: c.category.id,
}))
})
.sort((a, b) => new Date(a).getTime() - new Date(b).getTime())
Expand Down
8 changes: 4 additions & 4 deletions src/views/Other/Categories/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<template slot-scope="scope">
<el-button
@click.native.prevent="
$router.push('/posts/edit?id=' + scope.row._id)
$router.push('/posts/edit?id=' + scope.row.id)
"
type="text"
size="small"
Expand Down Expand Up @@ -191,16 +191,16 @@ export default class extends Vue {
}
async handleDelete(index: number) {
const _id = this.data[index]._id
await this.$api('Category').delete(_id as string)
const id = this.data[index].id
await this.$api('Category').delete(id as string)
this.$notice.success('删除成功')
this.fetch()
}
edit: false | string = false
handleEdit(row: CategoryRespDto) {
this.model = pick(row, ['slug', 'name', 'type'])
this.edit = row._id as string
this.edit = row.id as string
this.dialogVisible = true
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/Other/Files/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<template slot-scope="scope">
<el-popconfirm
title="确定删除吗?"
@onConfirm="handleDelete(scope.row._id)"
@onConfirm="handleDelete(scope.row.id)"
>
<el-button
type="text"
Expand Down
8 changes: 4 additions & 4 deletions src/views/Other/Friends/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<el-button
type="text"
size="small"
@click="handleApprove(scope.row._id)"
@click="handleApprove(scope.row.id)"
style="color: green"
v-if="tabActive === '1'"
>通过</el-button
Expand Down Expand Up @@ -266,8 +266,8 @@ export default class extends Vue {
}
async handleDelete(index: number) {
const _id = this.data[index]._id
await this.$api('Link').delete(_id as string)
const id = this.data[index].id
await this.$api('Link').delete(id as string)
this.$notice.success('删除成功')
this.fetch()
}
Expand All @@ -279,7 +279,7 @@ export default class extends Vue {
edit: false | string = false
handleEdit(row: LinkModel) {
this.model = pick(row, ['name', 'url', 'avatar', 'description', 'type'])
this.edit = row._id as string
this.edit = row.id as string
this.dialogVisible = true
}
Expand Down
6 changes: 3 additions & 3 deletions src/views/Other/Page/List.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<template slot-scope="scope">
<el-button
@click.native.prevent="
$router.push('/extra/page/edit?id=' + data[scope.$index]._id)
$router.push('/extra/page/edit?id=' + data[scope.$index].id)
"
type="text"
size="small"
Expand Down Expand Up @@ -84,8 +84,8 @@ export default class PageList extends Vue {
this.loading = false
}
async handleDelete(index: number) {
const _id = this.data[index]._id
await this.$api('Page').delete(_id as string)
const id = this.data[index].id
await this.$api('Page').delete(id as string)
this.$notice.success('删除成功')
this.fetchData()
}
Expand Down
Loading

0 comments on commit 50697e5

Please sign in to comment.