Skip to content

Commit

Permalink
Merge pull request rocboss#9 from pohunchn/main
Browse files Browse the repository at this point in the history
前端优化ts代码
  • Loading branch information
orziz authored May 27, 2022
2 parents ad7fc2d + 299bc5d commit bb04f38
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 33 deletions.
1 change: 1 addition & 0 deletions paopao-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
},
"devDependencies": {
"@types/node": "^17.0.35",
"@types/qrcode": "^1.4.2",
"@vitejs/plugin-vue": "^2.3.1",
"@vue/compiler-sfc": "^3.2.36",
"typescript": "^4.7.2",
Expand Down
4 changes: 2 additions & 2 deletions paopao-web/src/api/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ export const getPostComments = (params: NetParams.PostGetPostComments) => {
* - @param {array} tags 话题
* @returns Promise
*/
export const createPost = (data: any) => {
export const createPost = (data: NetParams.PostCreatePost) => {
return request({
method: 'post',
url: '/post',
data
});
}) as unknown as Promise<NetReq.PostCreatePost>;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion paopao-web/src/components/auth.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
message: '请输入密码',
},
{
validator(rule: FormItemRule, value: any) {
validator: (rule: FormItemRule, value: any) => {
return (
!!registerForm.password &&
registerForm.password.startsWith(
Expand Down
4 changes: 3 additions & 1 deletion paopao-web/src/components/comment-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ const replyAtUserID = ref(0);
const replyAtUsername = ref('');
const replyComposeRef = ref();

const emit = defineEmits(['reload']);
const emit = defineEmits<{
(e: "reload"): void
}>();
const props = withDefaults(defineProps<{
comment: Item.CommentProps
}>(), {})
Expand Down
4 changes: 3 additions & 1 deletion paopao-web/src/components/compose-comment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ import { getSuggestUsers } from '@/api/user';
import { parsePostTag } from '@/utils/content';
import type { MentionOption, UploadFileInfo, UploadInst } from 'naive-ui';

const emit = defineEmits(['post-success']);
const emit = defineEmits<{
(e: "post-success"): void
}>();
const props = withDefaults(defineProps<{
lock: number,
postId: number,
Expand Down
26 changes: 12 additions & 14 deletions paopao-web/src/components/compose-reply.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,19 @@ import { ref } from 'vue';
import { createCommentReply } from '@/api/post';
import { InputInst } from 'naive-ui';

const props = defineProps({
commentId: {
type: Number,
default: 0,
},
atUserid: {
type: Number,
default: 0,
},
atUsername: {
type: String,
default: '',
},
const props = withDefaults(defineProps<{
commentId: number,
atUserid: number,
atUsername: string,
}>(), {
commentId: 0,
atUserid: 0,
atUsername: ""
});
const emit = defineEmits(['reload', 'reset']);
const emit = defineEmits<{
(e: "reload"): void,
(e: "reset"): void
}>();
const inputInstRef = ref<InputInst>();
const showReply = ref(false);
const replyContent = ref('');
Expand Down
2 changes: 1 addition & 1 deletion paopao-web/src/components/compose.vue
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ import { parsePostTag } from '@/utils/content';
import type { MentionOption, UploadFileInfo, UploadInst } from 'naive-ui';

const emit = defineEmits<{
(e: 'post-success', post: AnyObject): void
(e: 'post-success', post: Item.PostProps): void
}>();

const store = useStore();
Expand Down
15 changes: 6 additions & 9 deletions paopao-web/src/components/main-nav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,12 @@ import { DarkModeOutlined, ChevronLeftRound } from '@vicons/material';
const store = useStore();
const router = useRouter();

const props = defineProps({
title: {
type: String,
default: '',
},
back: {
type: Boolean,
default: false,
},
const props = withDefaults(defineProps<{
title: string,
back: boolean,
}>(), {
title: "",
back: false
});
const switchTheme = (theme: boolean) => {
if (theme) {
Expand Down
4 changes: 3 additions & 1 deletion paopao-web/src/components/post-detail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ const showDelModal = ref(false);
const showLockModal = ref(false);
const loading = ref(false);

const emit = defineEmits(['reload']);
const emit = defineEmits<{
(e: "reload"): void
}>();

const post = computed({
get: () => {
Expand Down
5 changes: 4 additions & 1 deletion paopao-web/src/components/reply-item.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ const props = withDefaults(defineProps<{
reply: Item.ReplyProps,
}>(), {});
const store = useStore();
const emit = defineEmits(['focusReply', 'reload']);
const emit = defineEmits<{
(e: "focusReply", reply: Item.ReplyProps): void,
(e: "reload"): void
}>();

const focusReply = () => {
emit('focusReply', props.reply);
Expand Down
11 changes: 11 additions & 0 deletions paopao-web/src/types/NetParams.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,16 @@ declare module NetParams {
interface PostGetPostComments {
id: number
}

interface PostCreatePost {
contents: {
content: string,
type: number,
sort: number
}[],
tags: string[],
users: string[],
attachment_price: number
}

}
2 changes: 2 additions & 0 deletions paopao-web/src/types/NetReq.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,6 @@ declare module NetReq {
list: Item.PostProps[]
}

type PostCreatePost = Item.PostProps

}
3 changes: 2 additions & 1 deletion paopao-web/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="vite/client" />
/// <reference types="vue/ref-macros" />
/// <reference types="naive-ui/volar" />
/// <reference types="naive-ui/volar" />
/// <reference types="@types/qrcode" />
9 changes: 8 additions & 1 deletion paopao-web/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
resolved "https://registry.npmmirror.com/@types/lodash/-/lodash-4.14.181.tgz"
integrity sha512-n3tyKthHJbkiWhDZs3DkhkCzt2MexYHXlX0td5iMplyfwketaOeKboEVBqzceH7juqvEg3q5oUoBFxSLu7zFag==

"@types/node@^17.0.35", "@types/node@~17.0.5":
"@types/node@*", "@types/node@^17.0.35", "@types/node@~17.0.5":
version "17.0.35"
resolved "https://registry.npmmirror.com/@types/node/-/node-17.0.35.tgz"
integrity sha512-vu1SrqBjbbZ3J6vwY17jBs8Sr/BKA+/a/WtjRG+whKg1iuLFOosq872EXS0eXWILdO36DHQQeku/ZcL6hz2fpg==
Expand All @@ -114,6 +114,13 @@
resolved "https://registry.npmmirror.com/@types/parse-json/-/parse-json-4.0.0.tgz"
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==

"@types/qrcode@^1.4.2":
version "1.4.2"
resolved "https://registry.npmmirror.com/@types/qrcode/-/qrcode-1.4.2.tgz"
integrity sha512-7uNT9L4WQTNJejHTSTdaJhfBSCN73xtXaHFyBJ8TSwiLhe4PRuTue7Iph0s2nG9R/ifUaSnGhLUOZavlBEqDWQ==
dependencies:
"@types/node" "*"

"@vicons/carbon@^0.12.0":
version "0.12.0"
resolved "https://registry.npmmirror.com/@vicons/carbon/-/carbon-0.12.0.tgz"
Expand Down

0 comments on commit bb04f38

Please sign in to comment.