diff --git a/.eslintrc.json b/.eslintrc.json index c2f68ca..66ed365 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -21,13 +21,13 @@ "plugin:@angular-eslint/template/process-inline-templates" ], "rules": { - "@typescript-eslint/naming-convention": [ - "off" - ], +// "@typescript-eslint/naming-convention": [ +// "off" +// ], "prefer-arrow/prefer-arrow-functions": [ "off" ], -// "@typescript-eslint/member-ordering": [ +// "@typescript-eslint/member-ordering": [svn // "on" // ], "@typescript-eslint/ban-types": [ diff --git a/src/app/api/api.service.ts b/src/app/api/api.service.ts index 2641b92..4984176 100644 --- a/src/app/api/api.service.ts +++ b/src/app/api/api.service.ts @@ -20,7 +20,7 @@ export class ApiService { createArticle(article: ArticleReq) { article.id = null; - return this.httpService.Service
({ + return this.httpService.service
({ path: '/admin/article/create', contentType: 'application/json', method: 'POST', @@ -29,7 +29,7 @@ export class ApiService { } deleteArticle(id: number) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/article/del', method: 'DELETE', queryParam: {articleID: id} @@ -37,7 +37,7 @@ export class ApiService { } articles(pageNumber: number = 1, pageSize: number = 5) { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/articles', method: 'GET', queryParam: { @@ -48,7 +48,7 @@ export class ApiService { } adminArticles(pageNumber: number = 1, pageSize: number = 10) { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/admin/articles', method: 'GET', queryParam: { @@ -59,7 +59,7 @@ export class ApiService { } updateArticle(article: ArticleReq) { - return this.httpService.Service
({ + return this.httpService.service
({ path: '/admin/article/update', method: 'PUT', contentType: 'application/json', @@ -68,7 +68,7 @@ export class ApiService { } getArticle(articleId: number, is4Update: boolean = false) { - return this.httpService.Service
({ + return this.httpService.service
({ path: `/article/articleID/${articleId}`, method: 'GET', queryParam: {update: is4Update}, @@ -76,7 +76,7 @@ export class ApiService { } articlesByCategory(category: string, pageNumber: number = 1, pageSize: number = 10) { - return this.httpService.Service>({ + return this.httpService.service>({ path: `/articles/category/${category}`, method: 'GET', queryParam: { @@ -87,7 +87,7 @@ export class ApiService { } articlesByTag(tag: string, pageNumber: number = 1, pageSize: number = 10) { - return this.httpService.Service>({ + return this.httpService.service>({ path: `/articles/tag/${tag}`, method: 'GET', queryParam: { @@ -98,14 +98,14 @@ export class ApiService { } categories() { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/categories', method: 'GET' }); } createCategory(nameStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/category/create', method: 'POST', queryParam: {name: nameStr} @@ -113,7 +113,7 @@ export class ApiService { } deleteCategory(categoryId: number) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/category/del', method: 'DELETE', queryParam: {id: categoryId} @@ -121,7 +121,7 @@ export class ApiService { } updateCategory(categoryId: number, nameStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/category/update', method: 'PUT', queryParam: {id: categoryId, name: nameStr} @@ -129,7 +129,7 @@ export class ApiService { } tags(pageNumber: number = 1, pageSize: number = 10) { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/tags', method: 'GET', queryParam: { @@ -140,38 +140,38 @@ export class ApiService { } tagsNac() { - return this.httpService.Service<{ name: string; size: number }[]>({ + return this.httpService.service<{ name: string; size: number }[]>({ path: '/tags/nac', method: 'GET' }); } createTag(nameStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/tag/create', method: 'POST', queryParam: {name: nameStr} }); } - deleteTag(TagId: number) { - return this.httpService.Service({ + deleteTag(tagId: number) { + return this.httpService.service({ path: '/admin/tag/del', method: 'DELETE', - queryParam: {id: TagId} + queryParam: {id: tagId} }); } - updateTag(TagId: number, nameStr: string) { - return this.httpService.Service({ + updateTag(tagId: number, nameStr: string) { + return this.httpService.service({ path: '/admin/tag/update', method: 'PUT', - queryParam: {id: TagId, name: nameStr} + queryParam: {id: tagId, name: nameStr} }); } getCommentByTypeForAdmin(pagePath: string, pageNumber: number = 1, pageSize: number = 10) { - return this.httpService.Service>({ + return this.httpService.service>({ path: `/admin/comment/pagePath/${pagePath}`, method: 'GET', queryParam: { @@ -182,7 +182,7 @@ export class ApiService { } getCommentByTypeForUser(pagePath: string, pageNumber: number = 1, pageSize: number = 10) { - return this.httpService.Service>({ + return this.httpService.service>({ path: `/user/comment/pagePath/${pagePath}`, method: 'GET', queryParam: { @@ -193,7 +193,7 @@ export class ApiService { } deleteComment(idNumer: number) { - return this.httpService.Service({ + return this.httpService.service({ path: `/user/comment/del`, method: 'DELETE', queryParam: {id: idNumer} @@ -201,7 +201,7 @@ export class ApiService { } updateComment(commentReq: CommentReq) { - return this.httpService.Service({ + return this.httpService.service({ path: `/user/comment/update`, method: 'PUT', data: commentReq, @@ -210,7 +210,7 @@ export class ApiService { } comments(pagePath: string, pageSize: number = 10, pageNumber: number = 1) { - return this.httpService.Service>({ + return this.httpService.service>({ path: `/comment/pagePath/${pagePath}`, method: 'GET', queryParam: { @@ -221,7 +221,7 @@ export class ApiService { } createComment(commentReq: CommentReq) { - return this.httpService.Service({ + return this.httpService.service({ path: '/user/comment/create', method: 'POST', contentType: 'application/json', @@ -231,7 +231,7 @@ export class ApiService { counts() { - return this.httpService.Service<{ + return this.httpService.service<{ articleCount: number; visitorCount: number; categoryCount: number; @@ -244,7 +244,7 @@ export class ApiService { } adminLinks(pageSize: number = 10, pageNumber: number = 1) { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/admin/links', method: 'GET', queryParam: { @@ -255,7 +255,7 @@ export class ApiService { } createLink(linkReq: Link) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/links/create', method: 'POST', data: linkReq, @@ -264,14 +264,14 @@ export class ApiService { } deleteLink(idNumber: number) { - return this.httpService.Service({ + return this.httpService.service({ path: `/admin/links/del/${idNumber}`, method: 'DELETE', }); } updateLink(linkReq: Link) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/links/update', method: 'PUT', data: linkReq, @@ -280,7 +280,7 @@ export class ApiService { } applyLink(link: ApplyLinkReq) { - return this.httpService.Service({ + return this.httpService.service({ path: '/apply', method: 'POST', data: link, @@ -289,7 +289,7 @@ export class ApiService { } reapplyLink(keyStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/reapply', method: 'POST', queryParam: { @@ -299,14 +299,14 @@ export class ApiService { } links() { - return this.httpService.Service({ + return this.httpService.service({ path: '/links', method: 'GET', }); } verifyImgCode(codeStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/verCode', method: 'POST', queryParam: {code: codeStr} @@ -315,7 +315,7 @@ export class ApiService { login(loginReq: LoginReq) { - return this.httpService.Service({ + return this.httpService.service({ path: '/login', method: 'POST', contentType: 'application/json', @@ -324,14 +324,14 @@ export class ApiService { } logout() { - return this.httpService.Service({ + return this.httpService.service({ path: '/logout', method: 'GET', }); } registration(emailStr: string, pwd: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/registration', method: 'POST', queryParam: { @@ -342,7 +342,7 @@ export class ApiService { } resetPwd(idStr: string, emailStr: string, pwdStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/resetPwd', method: 'POST', queryParam: { @@ -354,7 +354,7 @@ export class ApiService { } emailVerify(idStr: string, emailStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/emailVerify', method: 'POST', queryParam: { @@ -366,7 +366,7 @@ export class ApiService { sendResetPwdEmail(emailStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/sendResetPwdEmail', method: 'POST', queryParam: {email: emailStr} @@ -374,7 +374,7 @@ export class ApiService { } sendVerifyEmail(emailStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/sendVerifyEmail', method: 'POST', queryParam: {email: emailStr} @@ -382,14 +382,14 @@ export class ApiService { } userInfo() { - return this.httpService.Service({ + return this.httpService.service({ path: '/user/userInfo', method: 'GET', }); } adminUpdateUser(user: User) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/user', method: 'PUT', data: user, @@ -398,14 +398,14 @@ export class ApiService { } deleteUser(id: number) { - return this.httpService.Service({ + return this.httpService.service({ path: `/admin/user/delete/${id}`, method: 'DELETE', }); } multipleDeleteUser(idArray: number[]) { - return this.httpService.Service<{ id: number; msg: string; status: boolean }[]>({ + return this.httpService.service<{ id: number; msg: string; status: boolean }[]>({ path: `/admin/user/delete`, method: 'DELETE', data: idArray, @@ -415,14 +415,14 @@ export class ApiService { // 获取邮件是否已注册 emailStatus(email: string) { - return this.httpService.Service({ + return this.httpService.service({ path: `/emailStatus/${email}`, method: 'GET' }); } updateUserInfo(descStr: string, disPlayNameStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/user/userInfo/update', method: 'PUT', queryParam: { @@ -433,7 +433,7 @@ export class ApiService { } adminUsers(pageSize: number = 10, pageNumber: number = 1) { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/admin/users', method: 'GET', queryParam: { @@ -444,14 +444,14 @@ export class ApiService { } visit() { - return this.httpService.Service({ + return this.httpService.service({ path: '/visit', method: 'POST' }); } adminVisitors(location: boolean = false, pageSize: number = 10, pageNumber: number = 1) { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/admin/visitor/page', method: 'GET', queryParam: { @@ -463,42 +463,42 @@ export class ApiService { } dayVisitCount() { - return this.httpService.Service({ + return this.httpService.service({ path: '/dayVisitCount', method: 'GET', }); } getLocalIp() { - return this.httpService.Service({ + return this.httpService.service({ path: '/ip', method: 'GET', }); } getIpLocation(ip: string) { - return this.httpService.Service({ + return this.httpService.service({ path: `/ip/${ip}`, method: 'GET', }); } visitorCount() { - return this.httpService.Service({ + return this.httpService.service({ path: `/visitor/count`, method: 'GET', }); } webUpdate() { - return this.httpService.Service<{ id: number; info: string; time: string }[]>({ + return this.httpService.service<{ id: number; info: string; time: string }[]>({ path: '/webUpdate', method: 'GET' }); } webUpdatePage(pageSize: number = 10, pageNumber: number = 1) { - return this.httpService.Service>({ + return this.httpService.service>({ path: '/webUpdate/pages', method: 'GET', queryParam: { @@ -509,7 +509,7 @@ export class ApiService { } lastestUpdate() { - return this.httpService.Service<{ + return this.httpService.service<{ lastUpdateTime: string; lastUpdateInfo: string; lastCommit: string; @@ -523,7 +523,7 @@ export class ApiService { } createWebUpdateInfo(infoStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/webUpdate/create', method: 'POST', queryParam: {info: infoStr} @@ -531,14 +531,14 @@ export class ApiService { } deleteWebUpdateInfo(idNumber: number) { - return this.httpService.Service({ + return this.httpService.service({ path: `/admin/webUpdate/del/${idNumber}`, method: 'DELETE', }); } updateWebUpdateInfo(idNumber: number, infoStr: string) { - return this.httpService.Service({ + return this.httpService.service({ path: '/admin/webUpdate/update', method: 'PUT', queryParam: {id: idNumber, info: infoStr} @@ -546,14 +546,14 @@ export class ApiService { } bingPic() { - return this.httpService.Service({ + return this.httpService.service({ path: '/bingPic', method: 'GET' }); } setPwd(pwdStr: string, newPwdStr: string, confirmPwdStr: string,) { - return this.httpService.Service({ + return this.httpService.service({ path: '/user/setPwd', method: 'POST', queryParam: { diff --git a/src/app/api/http/http.service.ts b/src/app/api/http/http.service.ts index 4d94bbc..1c1508a 100644 --- a/src/app/api/http/http.service.ts +++ b/src/app/api/http/http.service.ts @@ -20,12 +20,13 @@ export class HttpService { public getSubscriptionQueue = () => this.subscriptionQueue; - Service(request: RequestObj) { + service(request: RequestObj) { const errorService = this.injector.get(ErrorService); request.url = null; // 设置默认值 request.contentType = request.contentType == null ? 'application/x-www-form-urlencoded' : request.contentType; request.header = { + // eslint-disable-next-line @typescript-eslint/naming-convention 'Content-Type': request.contentType }; const token = this.localStorageService.getToken(); diff --git a/src/app/services/error.service.ts b/src/app/services/error.service.ts index 8616eeb..e2ebb79 100644 --- a/src/app/services/error.service.ts +++ b/src/app/services/error.service.ts @@ -11,9 +11,9 @@ import {LocalStorageService} from './local-storage.service'; providedIn: 'root' }) export class ErrorService { - private static HTTP_ERROR_COUNT: number = 0; - private readonly MAINTAIN_PAGE_PREFIX = '/maintain'; - private readonly ADMIN_PAGE_PREFIX = '/admin'; + private static httpErrorCount: number = 0; + private readonly maintainPagePrefix = '/maintain'; + private readonly adminPagePrefix = '/admin'; constructor(/*private httpService: HttpService,*/ private router: Router, @@ -27,7 +27,7 @@ export class ErrorService { if (!environment.production) { console.log('error=>', err, request); } - ErrorService.HTTP_ERROR_COUNT++; + ErrorService.httpErrorCount++; // this.httpService.getSubscriptionQueue().map(a => a.unsubscribe()) } @@ -38,7 +38,7 @@ export class ErrorService { if (response.code === -1 && response.msg === '重复请求') { return; } - if (this.componentStateService.currentPath === this.ADMIN_PAGE_PREFIX) { + if (this.componentStateService.currentPath === this.adminPagePrefix) { this.notification.create('error', `请求失败<${response.code}>`, `${response.msg}`); } /*** @@ -59,7 +59,7 @@ export class ErrorService { public checkConnection() { // The HTTP_ERROR_COUNT is start with 1 in this function - if (ErrorService.HTTP_ERROR_COUNT === 1) { + if (ErrorService.httpErrorCount === 1) { const req: RequestObj = { path: '/headerInfo', method: 'GET', @@ -68,10 +68,10 @@ export class ErrorService { this.injector.get(HttpService).get(req).subscribe({ next: () => null, error: () => { - if (this.componentStateService.currentPath !== this.MAINTAIN_PAGE_PREFIX) { - this.router.navigateByUrl(this.MAINTAIN_PAGE_PREFIX); + if (this.componentStateService.currentPath !== this.maintainPagePrefix) { + this.router.navigateByUrl(this.maintainPagePrefix); } - ErrorService.HTTP_ERROR_COUNT = 0; + ErrorService.httpErrorCount = 0; } }); } diff --git a/src/app/utils/color.ts b/src/app/utils/color.ts index fdcb973..862eb55 100644 --- a/src/app/utils/color.ts +++ b/src/app/utils/color.ts @@ -3,7 +3,7 @@ export class Color { fontColor: string; } -export const ColorList: Color[] = [ +export const COLOR_LIST: Color[] = [ {bgColor: '#7bcfa6', fontColor: '#000000'}, // 石青 {bgColor: '#bce672', fontColor: '#000000'}, // 松花色 {bgColor: '#ff8936', fontColor: '#000000'}, // 橘黄 @@ -13,16 +13,16 @@ export const ColorList: Color[] = [ {bgColor: '#177cb0', fontColor: '#ffffff'}, // 靛青 ]; -export const ColorListLength = ColorList.length; +export const COLOR_LIST_LENGTH = COLOR_LIST.length; /** * 获取一组随机颜色 * * @param count 数量 */ -export function RandomColor(count: number = 1): Color[] { +export function randomColor(count: number = 1): Color[] { const map = new Map(); - ColorList.forEach((color, index) => map.set(index, 0)); + COLOR_LIST.forEach((color, index) => map.set(index, 0)); const colorArray: Color[] = []; const oneRandomColor = () => { const minValue = Math.min.apply(null, Array.from(map.values())); @@ -30,7 +30,7 @@ export function RandomColor(count: number = 1): Color[] { const keyIndex = Math.floor(Math.random() * keys.length); const index = keys[keyIndex]; map.set(index, minValue + 1); - return ColorList[index]; + return COLOR_LIST[index]; }; for (let i = 0; i < count; i++) { colorArray.push(oneRandomColor()); diff --git a/src/app/view/admin/admin.component.ts b/src/app/view/admin/admin.component.ts index ebd3274..f183ab3 100644 --- a/src/app/view/admin/admin.component.ts +++ b/src/app/view/admin/admin.component.ts @@ -71,6 +71,7 @@ export class AdminComponent implements OnInit { const newPwd = this.resetPwdFormGroup && this.resetPwdFormGroup.value.newPwd; return control.value !== newPwd ? {pwdNotSame: true} : null; }; + // eslint-disable-next-line @typescript-eslint/naming-convention uploadHeader = (file: NzUploadFile): any | Observable<{}> => ({Authorization: this.localStorageService.getToken()}); showEditInfoModal() { diff --git a/src/app/view/write/write.component.ts b/src/app/view/write/write.component.ts index 6380c8a..8c02a70 100644 --- a/src/app/view/write/write.component.ts +++ b/src/app/view/write/write.component.ts @@ -243,6 +243,7 @@ export class WriteComponent implements OnInit, OnDestroy { .forEach(value => result.data.errFiles.push(value.originalFilename)); return JSON.stringify(result); }, + // eslint-disable-next-line @typescript-eslint/naming-convention setHeaders: () => ({Authorization: this.localStorageService.getToken()}) }, after: () => {