Browse Source

remove window as any (#4715)

pull/4762/head
陈帅 7 years ago
committed by GitHub
parent
commit
abb7fc3d2c
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/components/CopyBlock/index.tsx
  2. 4
      src/models/global.ts
  3. 65
      src/models/setting.ts
  4. 16
      src/typings.d.ts

2
src/components/CopyBlock/index.tsx

@ -20,7 +20,7 @@ const onBlockCopy = (label: string) => {
return;
}
const ga = window && (window as any).ga;
const ga = window && window.ga;
if (ga) {
ga('send', 'event', {
eventCategory: 'block',

4
src/models/global.ts

@ -128,8 +128,8 @@ const GlobalModel: GlobalModelType = {
setup({ history }): void {
// Subscribe history(url) change, trigger `load` action if pathname is `/`
history.listen(({ pathname, search }): void => {
if (typeof (window as any).ga !== 'undefined') {
(window as any).ga('send', 'pageview', pathname + search);
if (typeof window.ga !== 'undefined') {
window.ga('send', 'pageview', pathname + search);
}
});
},

65
src/models/setting.ts

@ -20,71 +20,6 @@ const updateTheme = (newPrimaryColor?: string) => {
}
};
/*
let lessNodesAppended: boolean;
const updateTheme: (primaryColor?: string) => void = primaryColor => {
// Don't compile less in production!
// preview.pro.ant.design only do not use in your production;
// preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
if (ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION !== 'site') {
return;
}
// Determine if the component is remounted
if (!primaryColor) {
return;
}
const hideMessage = message.loading('正在编译主题!', 0);
function buildIt() {
if (!(window as any).less) {
console.log('no less');
return;
}
setTimeout(() => {
(window as any).less
.modifyVars({
'@primary-color': primaryColor,
})
.then(() => {
hideMessage();
return true;
})
.catch(() => {
message.error('Failed to update theme');
hideMessage();
});
}, 200);
}
if (!lessNodesAppended) {
// insert less.js and color.less
const lessStyleNode = document.createElement('link');
const lessConfigNode = document.createElement('script');
const lessScriptNode = document.createElement('script');
lessStyleNode.setAttribute('rel', 'stylesheet/less');
lessStyleNode.setAttribute('href', '/color.less');
lessConfigNode.innerHTML = `
window.less = {
async: true,
env: 'production',
javascriptEnabled: true
};
`;
lessScriptNode.src = 'https://gw.alipayobjects.com/os/lib/less.js/3.8.1/less.min.js';
lessScriptNode.async = true;
lessScriptNode.onload = () => {
buildIt();
lessScriptNode.onload = null;
};
document.body.appendChild(lessStyleNode);
document.body.appendChild(lessConfigNode);
document.body.appendChild(lessScriptNode);
lessNodesAppended = true;
} else {
buildIt();
}
};
*/
const updateColorWeak: (colorWeak: boolean) => void = colorWeak => {
const root = document.getElementById('root');
if (root) {

16
src/typings.d.ts

@ -20,6 +20,22 @@ declare module 'nzh/cn';
declare module 'webpack-theme-color-replacer';
declare module 'webpack-theme-color-replacer/client';
// google analytics interface
interface GAFieldsObject {
eventCategory: string;
eventAction: string;
eventLabel?: string;
eventValue?: number;
nonInteraction?: boolean;
}
interface Window {
ga: (
command: 'send',
hitType: 'event' | 'pageview',
fieldsObject: GAFieldsObject | string,
) => void;
}
declare let ga: Function;
// preview.pro.ant.design only do not use in your production ;

Loading…
Cancel
Save