uni-app schema2code 功能一只loading

发布于 1周前 作者 h691938207 来自 Uni-App

uni-app schema2code 功能一只loading

产品分类

uniCloud/App

操作步骤

  1. 在云平台使用 opendb-contacts.schema.json 模版创建。
  2. 下载到编辑器。
  3. 右键使用 schema2code
  4. 一致 loading。

Hbuilder X 4.44 版本,schema2code 是最新插件。

预期结果

可以正常生成代码

实际结果

显示 loading

bug 描述

schema2code 一直 loading

运行日志如下:

2025-01-02 15:18:35.542 [INFO:] [PluginHost] 正在激活插件 uni-schema2code...
2025-01-02 15:18:35.561 [INFO:] [PluginHost] 插件 uni-schema2code 激活成功。
2025-01-02 15:18:38.333 [WARNING:] QLayout: Cannot add a null widget to QVBoxLayout/
2025-01-02 15:18:38.734 [INFO:] construct cef3 webview.
2025-01-02 15:18:42.061 [INFO:] Upgrade::isFallbackedVersion ?
2025-01-02 15:18:42.062 [INFO:] Upgrade::isFallbackedVersion return false
2025-01-02 15:18:42.062 [INFO:] Upgrade::canFallback::check( "C:/Program/HBuilderX.4.44.2024123110/HBuilderX/update/backup/root/hbuilder.root" ) exits?
2025-01-02 15:18:42.063 [INFO:] Upgrade::canFallback::check return false
2025-01-02 15:19:37.114 [WARNING:] [PluginHost] TypeScriptServerError: <semantic> TypeScript Server Error (5.2.2)
undefined
undefined
at TypeScriptServerError.create (C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\jsservice\out\tsServer\serverError.js:1:224)
at ProcessBasedTsServer.dispatchResponse (C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\jsservice\out\tsServer\server.js:1:3097)
at ProcessBasedTsServer.dispatchMessage (C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\jsservice\out\tsServer\server.js:1:1906)
at C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\jsservice\out\tsServer\server.js:1:1335
at e.fire (C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\plugin-manager\out.js:1:30225)
at Reader.onLengthData (C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\jsservice\out\tsServer\serverProcess.electron.js:1:2411)
at Socket.<anonymous> (C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\jsservice\out\tsServer\serverProcess.electron.js:1:2058)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9) {
serverId: 'semantic',
version: TypeScriptVersion {
source: 'ts-nightly-extension',
path: 'C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\node_modules\typescript\lib\tsserver.js',
apiVersion: API {
displayName: '5.2.2',
version: '5.2.2',
fullVersionString: '5.2.2'
},
_pathLabel: ''
},
response: {
seq: 0,
type: 'response',
command: 'unknown',
request_seq: 5,
success: false,
message: 'Unrecognized JSON command: onReportMessage',
_serverType: 'semantic'
},
serverMessage: undefined,
serverStack: undefined,
sanitizedStack: undefined
}
2025-01-02 15:21:37.112 [WARNING:] [PluginHost] TypeScriptServerError: <semantic> TypeScript Server Error (5.2.2)
undefined
undefined
at TypeScriptServerError.create (C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\jsservice\out\tsServer\serverError.js:1:224)
at ProcessBasedTsServer.dispatchResponse (C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\jsservice\out\tsServer\server.js:1:3097)
at ProcessBasedTsServer.dispatchMessage (C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\jsservice\out\tsServer\server.js:1:1906)
at C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\jsservice\out\tsServer\server.js:1:1335
at e.fire (C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\plugin-manager\out.js:1:30225)
at Reader.onLengthData (C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\jsservice\out\tsServer\serverProcess.electron.js:1:2411)
at Socket.<anonymous> (C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\jsservice\out\tsServer\serverProcess.electron.js:1:2058)
at Socket.emit (node:events:517:28)
at addChunk (node:internal/streams/readable:368:12)
at readableAddChunk (node:internal/streams/readable:341:9) {
serverId: 'semantic',
version: TypeScriptVersion {
source: 'ts-nightly-extension',
path: 'C:\Program\HBuilderX.4.44.2024123110\HBuilderX\plugins\hbuilderx-language-services\node_modules\typescript\lib\tsserver.js',
apiVersion: API {
displayName: '5.2.2',
version: '5.2.2',
fullVersionString: '5.2.2'
},
_pathLabel: ''
},
response: {
seq: 0,
type: 'response',
command: 'unknown',
request_seq: 6,
success: false,
message: 'Unrecognized JSON command: onReportMessage',
_serverType: 'semantic'
},
serverMessage: undefined,
serverStack: undefined,
sanitizedStack: undefined
}

图片

开发环境、版本号、项目创建方式

信息
开发环境 HBuilder X 4.44
版本号 HBuilderX 4.44.2024123110
项目创建方式 使用 opendb-contacts.schema.json 模版创建

3 回复

重启 HBuilderX 试试


重新启动了,并且重新安装了,问题每次必现

在处理 uni-appschema2code 功能时,如果遇到一直 loading 的情况,这通常指示着某些环节出现了阻塞或异常。以下是一些可能的代码示例和调试方法,帮助你定位和解决问题。注意,这些代码示例主要关注 schema2code 功能的具体实现和调试技巧,而不是直接给出具体的修复建议。

1. 检查 Schema 文件

首先,确保你的 schema 文件格式正确且没有语法错误。以下是一个简单的 schema 示例:

{
  "pages": [
    {
      "path": "pages/index/index",
      "style": {
        "navigationBarTitleText": "首页"
      }
    }
  ],
  "window": {
    "navigationBarBackgroundColor": "#ffffff",
    "navigationBarTextStyle": "black",
    "navigationBarTitleText": "uni-app",
    "backgroundColor": "#eeeeee",
    "backgroundTextStyle": "light"
  }
}

2. 检查 schema2code 调用代码

确保你在调用 schema2code 时传递了正确的参数。以下是一个假设的调用示例:

uni.request({
  url: 'https://your-server.com/schema2code', // 替换为你的实际接口地址
  method: 'POST',
  data: {
    schema: JSON.stringify(yourSchema) // 将 schema 对象转换为 JSON 字符串
  },
  success: (res) => {
    console.log('Generated code:', res.data);
  },
  fail: (err) => {
    console.error('Failed to generate code:', err);
  }
});

3. 服务器端调试

如果 schema2code 功能依赖于服务器端处理,检查服务器端的日志和代码,确保没有异常抛出,并且请求能够正确处理。以下是一个简单的 Node.js 服务器端示例:

const express = require('express');
const app = express();
const bodyParser = require('body-parser');

app.use(bodyParser.json());

app.post('/schema2code', (req, res) => {
  const schema = JSON.parse(req.body.schema);
  // 处理 schema 并生成代码(此处省略具体实现)
  const generatedCode = '// Your generated code here';
  res.json({ code: generatedCode });
});

app.listen(3000, () => {
  console.log('Server is running on port 3000');
});

4. 客户端超时设置

如果服务器端处理时间较长,考虑在客户端设置请求超时,以便更好地处理可能的阻塞情况:

const requestOptions = {
  url: 'https://your-server.com/schema2code',
  method: 'POST',
  data: { schema: JSON.stringify(yourSchema) },
  timeout: 10000 // 设置超时时间为10秒
};

uni.request(requestOptions).then(...).catch(...);

通过上述步骤,你可以更好地定位和解决 schema2code 功能一直 loading 的问题。如果问题依旧存在,建议进一步检查网络请求、服务器日志以及可能的代码异常。

回到顶部