protected buildThirdPartyAttr()

in packages/shared/src/miniapp/template.ts [220:254]


  protected buildThirdPartyAttr(attrs: Set<string>, patcher: Record<string, string> = {}) {
    return Array.from(attrs).reduce((str, attr) => {
      if (attr.startsWith('@')) {
        // vue2
        let value = attr.slice(1);
        if (value.indexOf('-') > -1) {
          value = `:${value}`;
        }
        return `${str}bind${value}="eh" `;
      } else if (attr.startsWith('bind')) {
        return `${str}${attr}="eh" `;
      } else if (attr.startsWith('on')) {
        // react, vue3
        let value = toKebabCase(attr.slice(2));
        if (value.indexOf('-') > -1) {
          // 兼容如 vant 某些组件的 bind:a-b 这类属性
          value = `:${value}`;
        }
        return `${str}bind${value}="eh" `;
      } else if (attr === 'class') {
        return `${str}class="{{i.${Shortcuts.Class}}}" `;
      } else if (attr === 'style') {
        return `${str}style="{{i.${Shortcuts.Style}}}" `;
      }

      const patchValue = patcher[attr];
      if (isBooleanStringLiteral(patchValue) || isNumber(patchValue) || isString(patchValue)) {
        const propValue = this.supportXS
          ? `xs.b(i.${toCamelCase(attr)},${patchValue})`
          : `i.${toCamelCase(attr)}===undefined?${patchValue}:i.${toCamelCase(attr)}`;
        return `${str}${attr}="{{${propValue}}}" `;
      }
      return `${str}${attr}="{{i.${toCamelCase(attr)}}}" `;
    }, '');
  }