Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: 输出 web externalClasses功能修复 #1661

Merged
merged 16 commits into from
Oct 28, 2024
Merged

Conversation

Blackgan3
Copy link
Collaborator

调整输出web externalClasses实现逻辑,完全走Mpx内部处理,不再经由vue处理

@@ -5,5 +5,6 @@ module.exports = {
RESOLVE_IGNORED_ERR: new Error('Resolve ignored!'),
JSON_JS_EXT: '.json.js',
MPX_ROOT_VIEW: 'mpx-root-view', // 根节点类名
MPX_APP_MODULE_ID: 'mpx-app-scope' // app文件moduleId
MPX_APP_MODULE_ID: 'mpx-app-scope', // app文件moduleId
P_MODULE_ID: 'p-module-id'
Copy link
Collaborator

@hiyuki hiyuki Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

改成__pid吧

const dynamicClass = getAndRemoveAttr(el, ':' + className).val
if (dynamicClass) {
attrValue = dynamicClass
attrName = ':' + className
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这还给他覆盖了。。。会出bug。。。
不用getAndRemove,你就检查一下attrsMap中有就行。。。

const reg = new RegExp('\\b' + className + '\\b', 'g')
const replacementClassName = dash2hump(className)
const replacementModuleId = dash2hump(P_MODULE_ID)
classLikeAttrValue = classLikeAttrValue.replace(reg, `{{${replacementClassName}||''}} {{${replacementModuleId}}}`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你这不用每次替换都扔一个moduleId啊

name: 'class',
value: classNames.join(' ')
name: ':' + classLikeAttrName,
value: `['${classNames.join(' ')}', ${replacements.join(' ')}, $attrs[${stringify(P_MODULE_ID)}]].join(' ')`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[${classname},${replacements}].join(' ')

if (dynamicClass) replacements.push(dynamicClass)

} else if (classNames.length) {
// 静态class拼接
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全走动态就可以

if (staticClass) {
const classNames = staticClass.split(/\s+/)
function processWebClass (classLikeAttrName, classLikeAttrValue, el, options) {
const classNames = classLikeAttrValue.split(/\s+/)
const replacements = []
options.externalClasses.forEach((className) => {
Copy link
Collaborator

@hiyuki hiyuki Oct 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

classNames = classNames.map((className)=>{
if(extenalClasses.includes(className)) return `($attrs[${stringify(className)}] || '')`
return stringify(className)
})

classNames.push(`($attrs[${stringify(PMID)}] || '')`)

value = `[${classNames}].join(' ')`

}])
}
} else {
Copy link
Collaborator

@hiyuki hiyuki Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没必要拆这么开,

if(classLikeAttrName === 'class') {
      const dynamicClass = getAndRemoveAttr(el, ':class').val
      if (dynamicClass) classNames.push(dynamicClass)
      addAttrs(el, [{
        name: ':class',
        value: `[${classNames}]`
      }])
} else {
      addAttrs(el, [{
        name: ':' + classLikeAttrName,
        value: `[${classNames}].join(' ')`
      }])
}

@hiyuki hiyuki merged commit 9a982e2 into master Oct 28, 2024
6 checks passed
@hiyuki hiyuki deleted the feat-web-scoped-by-mpx branch October 28, 2024 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants