amis icon indicating copy to clipboard operation
amis copied to clipboard

InputRichText统计的字符有问题

Open thinkingc opened this issue 11 months ago • 1 comments

描述问题:

InputRichText统计的字符有问题.

截图或视频:

Image

如何复现(请务必完整填写下面内容):

  1. 你是如何使用 amis 的? sdknpm其他...

  2. amis 版本是什么?请先在最新 beta 版本测试问题是否存在

  3. 粘贴有问题的完整 amis schema 代码:

{
  "type": "page",
  "body": {
    "type": "form",
    "api": "/amis/api/mock2/form/saveForm",
    "body": [
      {
        "type": "input-rich-text",
        "name": "rich",
        "label": "Rich Text"
      }
    ]
  }
}
  1. 操作步骤 1、聚焦,连续输入多个a 2、观察右下角,展示的字符数有问题。当点击字符数后,字符数更新

thinkingc avatar May 06 '25 12:05 thinkingc

试了下 点击后是字符,默认显示是字 应该默认显示的是中文字数,字符才是真正的你想看到的字数 帮你搞了个解决方法,原理是加载完成后帮你点击一下字数,就默认显示字符了

{
  "type": "page",
  "body": [
    {
      "type": "form",
      "api": "/amis/api/mock2/form/saveForm",
      "body": [
        {
          "type": "input-rich-text",
          "name": "rich",
          "label": "Rich Text",
          "id": "u:c257075b6d3c",
          "vendor": "tinymce",
          "options": {
            "plugins": "advlist,autolink,link,image,lists,charmap,preview,anchor,pagebreak,searchreplace,wordcount,visualblocks,visualchars,code,fullscreen,insertdatetime,media,nonbreaking,table,emoticons,template,help",
            "toolbar": "undo redo bold italic backcolor alignleft formatselect aligncenter alignright alignjustify bullist numlist outdent indent removeformat help",
            "menubar": true
          }
        }
      ],
      "id": "u:bd206f81ec62",
      "actions": [
        {
          "type": "submit",
          "label": "提交",
          "primary": true,
          "id": "u:55e757a5351d"
        }
      ],
      "feat": "Insert",
      "dsType": "api",
      "labelAlign": "left"
    }
  ],
  "id": "u:82e74885313f",
  "asideResizor": false,
  "pullRefresh": {
    "disabled": true
  },
  "onEvent": {
    "init": {
      "weight": 0,
      "actions": [
        {
          "ignoreError": false,
          "script": "let attempts = 0;\nconst check = setInterval(() => {\n  const b = document.querySelector(\"button.tox-statusbar__wordcount\");\n  attempts > 50 ? clearInterval(check) : b && (clearInterval(check), setTimeout(() => b.click(), 100));\n}, 100);",
          "actionType": "custom",
          "args": {}
        }
      ]
    }
  }
}

Image

主要代码:

let attempts = 0;
const check = setInterval(() => {
  const b = document.querySelector("button.tox-statusbar__wordcount");
  attempts > 50 ? clearInterval(check) : b && (clearInterval(check), setTimeout(() => b.click(), 100));
}, 100);

欢迎加入最大的,人数最多的,含佬量极高的社区群 Amis社区交流群【QQ1群】:717791727 Amis社区交流群【QQ2群】:721182449

lhtuling avatar May 12 '25 11:05 lhtuling