Skip to content

Commit

Permalink
fontsize支持一多适配
Browse files Browse the repository at this point in the history
  • Loading branch information
58liuyang committed May 6, 2024
1 parent 823d140 commit 3a16e4d
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions packages/taro-platform-harmony-hybrid/src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,56 @@ export default class H5 extends TaroPlatformWeb {
return args
})

// 修改htmlWebpackPlugin插件的script脚本
chain.plugin('htmlWebpackPlugin').tap((args)=>{

Check failure on line 133 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Missing space before =>

Check failure on line 133 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Missing space after =>

Check failure on line 133 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Missing space before =>

Check failure on line 133 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Missing space after =>

Check failure on line 133 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (windows-latest)

Missing space before =>

Check failure on line 133 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (windows-latest)

Missing space after =>

Check failure on line 133 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (macos-11)

Missing space before =>

Check failure on line 133 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (macos-11)

Missing space after =>
const options = this.config?.postcss?.pxtransform?.config || {}
// const max = options?.maxRootSize ?? 40
// const min = options?.minRootSize ?? 20
const baseFontSize = options?.baseFontSize || 20//(min > 1 ? min : 20)

Check failure on line 137 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Expected space or tab after '//' in comment

Check failure on line 137 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Expected space or tab after '//' in comment

Check failure on line 137 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (windows-latest)

Expected space or tab after '//' in comment

Check failure on line 137 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (macos-11)

Expected space or tab after '//' in comment
const designWidth = (input => typeof this.config.designWidth === 'function'
? this.config.designWidth(input)
: this.config.designWidth)(baseFontSize)
const rootValue = baseFontSize / this.config.deviceRatio![designWidth!] * 2
let htmlScript = ''
if ((this.config?.targetUnit ?? 'rem') === 'rem') {
htmlScript = `
!function(n){
function f(){
var e=n.document.documentElement;
var w=Math.floor(e.getBoundingClientRect().width);
if(w < 600){
// 手机-竖屏,缩放策略为“自动缩放”
var x=${rootValue}*w/${designWidth};
e.style.fontSize=x+"px"
}
else if(w < 840) {
// 折叠屏、Pad竖屏,缩放策略为“依据设计尺寸,大小不变”
w = ${designWidth} / 2
var x=${rootValue}*w/${designWidth};
e.style.fontSize=x+"px"
}
else if(w < 1440){
// Pad(模屏)、2in1(默认),缩放策略为“依据设计尺寸,大小不变”
w = ${designWidth} / 2
var x=${rootValue}*w/${designWidth};
e.style.fontSize=x+"px"
}
else {
// 2in1(全屏),缩放策略为“依据设计尺寸,大小不变”
w = ${designWidth} / 2
var x=${rootValue}*w/${designWidth};
e.style.fontSize=x+"px"
}
}
n.addEventListener("resize",(function(){f()}));
f()
}(window);
`
}
args[0].script = htmlScript
return args;

Check failure on line 179 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Extra semicolon

Check failure on line 179 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (ubuntu-latest)

Extra semicolon

Check failure on line 179 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (windows-latest)

Extra semicolon

Check failure on line 179 in packages/taro-platform-harmony-hybrid/src/program.ts

View workflow job for this annotation

GitHub Actions / Testing on Node.js 16.x (macos-11)

Extra semicolon
})

// Note: 本地调试 stencil 组件库时,如果启用 sourceMap 则需要相关配置
chain.module
.rule('map')
Expand Down

0 comments on commit 3a16e4d

Please sign in to comment.