From 3b03f87a02458f719e2eb4bf112a13441b427d14 Mon Sep 17 00:00:00 2001 From: ‘chensiAb’ <‘chenchenco03@163.com’> Date: Tue, 25 Mar 2025 13:54:34 +0800 Subject: [PATCH] Merge branch 'master' of ssh://dev.zhiheiot.com:29418/mob-components --- _cursor.ai/prompts/创建一个请求.prompts.md | 79 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 79 insertions(+), 0 deletions(-) diff --git "a/_cursor.ai/prompts/\345\210\233\345\273\272\344\270\200\344\270\252\350\257\267\346\261\202.prompts.md" "b/_cursor.ai/prompts/\345\210\233\345\273\272\344\270\200\344\270\252\350\257\267\346\261\202.prompts.md" new file mode 100644 index 0000000..6021b06 --- /dev/null +++ "b/_cursor.ai/prompts/\345\210\233\345\273\272\344\270\200\344\270\252\350\257\267\346\261\202.prompts.md" @@ -0,0 +1,79 @@ +# 指令:创建一个请求 + +我们以会员信息为例新开请求 + +## 第一步:添加请求数据JSON文件 + +在 mocks 文件夹下新建数据文件 `getUserInfo.json` +``` +src/public/static/项目名称/mocks/user/getUserInfo.json +``` + +内容为: +```json +{ + "state": { + "code": 2000, + "msg": "OK" + }, + "data": { + } +} +``` + + +## 第二步:在请求集中添加请求 + +在 `src/fetchers` 文件夹下,以 F 开头的请求请求集中,添加一个独立的请求方法,方法名和 json 文件一样 + +例如:在 `FUser.js` 中添加 `getUserInfo` +```js +class FUser extends Fetcher { + constructor() { + super({ + urlPrefix: ['/api/user/', '/mini/'], + }); + } + + // 读取会员信息 + getUserInfo(user) { + const url = this.spellURL('getUserInfo', 'User/Info'); + const send = { + ...this.transKeyName('underline', user), + }; + return this.post(url, send); + } + +} + +export const $fetchUser = new FUser(); +``` + +如果创建一个全新的请求集,那么构造器的 urlPrefix 参数的第一个值为 `'/api/分类名/'` + +## 第三步:在数据控制器中调用请求 + +在需要的需要的数据控制文件中: +- 使用 `import` 引入需要的使用的请求集 +- 在类中,添加一个独立方法,调用对应的数据请求 + +```js +import { $fetchUser } from '@fetchers/FUser'; + +export class PLogisSender extends Pilot { + + // 加载用户详情 + onLoadUserDetail(user) { + Taro.showLoading(); + $fetchUser.getUserDetail(user) + .then(res => { + Taro.hideLoading(); + if (!res) { + return; + } + this.userDetail = res.detail; + }); + } + +} +``` -- Gitblit v1.9.1