Skip to content

Commit

Permalink
fixbug: 修复ts检查
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Aug 21, 2022
1 parent 62e3543 commit edf828e
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 75 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions mock/_createProductionServer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createProdMockServer } from 'vite-plugin-mock/es/createProdMockServer';

const modules = import.meta.globEager('./**/*.ts');
const modules: Recordable = import.meta.glob('./**/*.ts', { eager: true });

const mockModules: any[] = [];
const mockModules: Recordable[] = [];
Object.keys(modules).forEach((key) => {
if (key.includes('/_')) {
return;
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
"build": "vite build",
"staging": "vite build --mode staging",
"serve": "vite preview",
"type:check": "vue-tsc --noEmit --skipLibCheck",
"preview": "npm run build && vite preview",
"preview:dist": "vite preview",
"log": "conventional-changelog -p angular -i CHANGELOG.md -s",
"test:gzip": "http-server dist --cors --gzip -c-1",
"test:br": "http-server dist --cors --brotli -c-1",
"lint:eslint": "eslint \"{src,mock}/**/*.{vue,ts,js,tsx,jsx}\" --fix",
Expand Down Expand Up @@ -70,8 +74,8 @@
"@vitejs/plugin-vue-jsx": "^2.0.0",
"@vue/compiler-sfc": "^3.2.37",
"autoprefixer": "^10.4.8",
"babel-eslint": "^10.1.0",
"commitizen": "^4.2.5",
"conventional-changelog-cli": "^2.2.2",
"crypto-js": "^4.1.1",
"cz-conventional-changelog": "^3.3.0",
"cz-customizable": "^6.9.1",
Expand Down
49 changes: 24 additions & 25 deletions src/components/CountTo/src/normal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,33 @@ export default defineComponent({
state.rAF = requestAnimationFrame(count);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
function pauseResume() {
if (state.paused) {
resume();
state.paused = false;
} else {
pause();
state.paused = true;
}
}
// function pauseResume() {
// if (state.paused) {
// resume();
// state.paused = false;
// } else {
// pause();
// state.paused = true;
// }
// }

function pause() {
cancelAnimationFrame(state.rAF);
}
// function pause() {
// cancelAnimationFrame(state.rAF);
// }

function resume() {
state.startTime = null;
state.localDuration = +(state.remaining as number);
state.localStartVal = +(state.printVal as number);
requestAnimationFrame(count);
}
// function resume() {
// state.startTime = null;
// state.localDuration = +(state.remaining as number);
// state.localStartVal = +(state.printVal as number);
// requestAnimationFrame(count);
// }

// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
function reset() {
state.startTime = null;
cancelAnimationFrame(state.rAF);
state.displayValue = formatNumber(props.startVal);
}
// // eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
// function reset() {
// state.startTime = null;
// cancelAnimationFrame(state.rAF);
// state.displayValue = formatNumber(props.startVal);
// }

function count(timestamp: number) {
const { useEasing, easingFn, endVal } = props;
Expand Down
33 changes: 17 additions & 16 deletions src/components/SeamlessScroll/utils.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
const iWindow: Recordable = window;
/**
* @desc AnimationFrame简单兼容hack
*/
export const animationFrame = () => {
window.cancelAnimationFrame = (() => {
iWindow.cancelAnimationFrame = (() => {
return (
window.cancelAnimationFrame ||
window.webkitCancelAnimationFrame ||
window.mozCancelAnimationFrame ||
window.oCancelAnimationFrame ||
window.msCancelAnimationFrame ||
function (id) {
return window.clearTimeout(id);
iWindow.cancelAnimationFrame ||
iWindow.webkitCancelAnimationFrame ||
iWindow.mozCancelAnimationFrame ||
iWindow.oCancelAnimationFrame ||
iWindow.msCancelAnimationFrame ||
function (id: number) {
return iWindow.clearTimeout(id);
}
);
})();
window.requestAnimationFrame = (function () {
iWindow.requestAnimationFrame = (function () {
return (
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function (callback) {
return window.setTimeout(callback, 1000 / 60);
iWindow.requestAnimationFrame ||
iWindow.webkitRequestAnimationFrame ||
iWindow.mozRequestAnimationFrame ||
iWindow.oRequestAnimationFrame ||
iWindow.msRequestAnimationFrame ||
function (callback: void) {
return iWindow.setTimeout(callback, 1000 / 60);
}
);
})();
Expand Down
1 change: 1 addition & 0 deletions src/hooks/web/useI18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export function translateI18n(message: any = '') {
}
const key = message.split('.')[0];
if (key && Object.keys(i18n.global.messages.value[locale]).includes(key)) {
// @ts-ignore
return i18n.global.t(message);
}
return message;
Expand Down
12 changes: 3 additions & 9 deletions src/locales/en/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
const config = import.meta.globEager('./modules/*.ts');
import { defaultFilePath } from '../utils';

const messages: Recordable = {};
Object.keys(config).forEach((key) => {
const name: RegExpMatchArray = key.match(/^\.\/([\s\S]+)\/([\s\S]+)\.ts$/) || [];
const valueName = name[2];
const value = config[key].default || {};
messages[valueName] = value;
});
const config: Recordable = import.meta.glob('./modules/*.ts', { eager: true });

export const name = 'English';

export default messages;
export default defaultFilePath(config);
7 changes: 4 additions & 3 deletions src/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ interface localesType {
locale: string;
}

const config: Recordable = import.meta.globEager('./**/index.ts');
const config: Recordable = import.meta.glob('./**/index.ts', { eager: true });

const messages: any = {};
const messages: Recordable = {};
const localesList: localesType[] = [];
Object.keys(config).forEach((key) => {
const name: any = key.match(/^\.\/([\s\S]+)\/index.ts$/);
const name: RegExpMatchArray = key.match(/^\.\/([\s\S]+)\/index.ts$/) || [];
if (!name[1]) return;
messages[name[1]] = config[key].default;
localesList.push({ name: config[key].name, locale: name[1] });
});
Expand Down
13 changes: 13 additions & 0 deletions src/locales/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export type Messages = { [key: string]: string };

export const defaultFilePath = (config: Recordable) => {
const messages: Messages = {};
Object.keys(config).forEach((key) => {
const name: RegExpMatchArray = key.match(/^\.\/([\s\S]+)\/([\s\S]+)\.ts$/) || [];
const valueName = name[2];
const value = config[key].default || {};
messages[valueName] = value;
});

return messages;
};
13 changes: 3 additions & 10 deletions src/locales/zh-ch/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
const config = import.meta.globEager('./modules/*.ts');
import { defaultFilePath } from '../utils';

const messages: Recordable = {};

Object.keys(config).forEach((key) => {
const name: RegExpMatchArray = key.match(/^\.\/([\s\S]+)\/([\s\S]+)\.ts$/) || [];
const valueName = name[2];
const value = config[key].default || {};
messages[valueName] = value;
});
const config: Recordable = import.meta.glob('./modules/*.ts', { eager: true });

export const name = '中文简体';

export default messages;
export default defaultFilePath(config);
2 changes: 1 addition & 1 deletion src/router/modules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function configRouteList() {
const whiteRouteModulesList: AppRouteRecordRaw[] = []; // 不参与菜单处理的路由

// 自动查找路由配置文件
const modules = import.meta.globEager('./**/*.ts');
const modules: Recordable = import.meta.glob('./**/*.ts', { eager: true });
Object.keys(modules).forEach((key) => {
const mod = modules[key].default;
if (!mod) return;
Expand Down
2 changes: 1 addition & 1 deletion src/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function initAsyncRoute(power: string) {
// 更具接口返回的路由列表生成新的理由
routeList = handleRouteList(sortRouteList(sidebarRouteList), res.data);
privilegeRouting(
router.options.routes,
router.options.routes as RouteRecordRaw[],
formatFlatteningRoutes(routeList) as AppRouteRecordRaw[],
);
usePermissionStoreHook().setWholeMenus(routeList);
Expand Down
2 changes: 1 addition & 1 deletion src/views/components/calendar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
const value = ref<Date>();
const DateItem = (v) => {
const DateItem = (v: Recordable) => {
const { day } = v.data;
const date = new Date(day);
var year = date?.getFullYear();
Expand Down
7 changes: 6 additions & 1 deletion src/views/index/components/WeDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,12 @@
name: 'WeDetails',
});
const lists = ref([
const lists = ref<
{
type: '' | 'success' | 'warning' | 'info' | 'danger';
label: string;
}[]
>([
{ type: '', label: '吃饭' },
{ type: 'success', label: '睡觉' },
{ type: 'info', label: '打游戏' },
Expand Down
5 changes: 3 additions & 2 deletions src/views/useradmin/refSyntax/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
<script setup lang="ts">
// import { useMouse } from '@vueuse/core';
// import { ref } from 'vue';
import { $ref } from 'vue/macros';
const stem = $ref('admin');
let stem = $ref('admin');
// 公共方法里面使用$ref导出ref
function useMouse() {
Expand All @@ -20,7 +21,7 @@
}
// 通过
const { x, y } = $(useMouse());
let { x, y } = $(useMouse());
console.log(x);
// // $ref解构方法返回的ref
// const { x, y } = $(useMouse());
Expand Down
1 change: 1 addition & 0 deletions tsconfig.tsbuildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"4.7.4"}
1 change: 1 addition & 0 deletions types/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference types="vue/macros-global" />
declare module '*.vue' {
import { DefineComponent } from 'vue';
const Component: DefineComponent<{}, {}, any>;
Expand Down
6 changes: 3 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://vitejs.dev/config/

import { UserConfig, ConfigEnv, loadEnv } from 'vite';
import { UserConfig, ConfigEnv } from 'vite';

import { createVitePlugins } from './build/vite/plugin';
import { createViteResolve } from './build/vite/resolve';
Expand All @@ -11,9 +11,9 @@ import { createViteCSS } from './build/vite/css';

export default (configEnv: ConfigEnv): UserConfig => {
const { mode, command } = configEnv;
const root = process.cwd();
// const root = process.cwd();

const _env = loadEnv(mode, root);
// const _env = loadEnv(mode, root);

const isBuild = command === 'build';

Expand Down

0 comments on commit edf828e

Please sign in to comment.