# demos **Repository Path**: zjjw/demos ## Basic Information - **Project Name**: demos - **Description**: 公共组件,公共服务,公共方法,原子操作使用示例等。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 5 - **Created**: 2021-01-23 - **Last Updated**: 2021-01-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 开发步骤 ## 准备 ### 环境 [Node.js安装](https://feidao-edu.gitee.io/docs/taoqf/2018022301.html) ### 项目 #### 下载依赖包 ```sh cnpm i ``` ## 页面开发 运行命令 ```sh cnpm test ``` ## 服务依赖 如xxx是生成验证码原子操作依赖的,需要添加到项目中,方法为: 1. 安装依赖 ```sh cnpm i xxx -D ``` 2. 项目依赖package-service.json添加 ```json "dependencies": { "xxx": "*" } ``` ## 项目发布 一键发布 ```sh ./publish.sh ``` ## 第三方依赖 ### 导出pdf - 参数 - `orientation` pdf版式('landscape': 横版,'portrait': 竖版;默认是竖版) - `attachment` pdf文件名称(完整文件名称,例如:ceshi.pdf) ```js import render from '@feidao/web/atom/nodejs/render/render'; // 在页面上显示pdf文件内容,则不能传入参数attachment // 要展示的pdf为横版 const url = 'http://192.168.40.196/flippedclass/print.pdf?orientation=landscape'; // 竖版 const url = 'http://192.168.40.196/flippedclass/print.pdf?orientation=portrait'; const url = 'http://192.168.40.196/flippedclass/print.pdf'; // 直接对pdf文件进行下载,需传入参数attachment const url = 'http://192.168.40.196/flippedclass/print.pdf?attachment=ceshi.pdf'; // 渲染 render(fd.data.node, url, 'docx', 'p01'); ``` - 名称 - `jsreport-phantom-pdf` - `jsreport-core` - `inline-source` ```安装 在package-service.json里的dependencies里添加` "jsreport-phantom-pdf": "latest", "inline-source": "latest", "jsreport-core": "latest" ` 在package.json里的devDependencies里添加` "jsreport-phantom-pdf": "latest", "inline-source": "latest", "jsreport-core": "latest" ` ``` ### 导出xlsx - 参数 - `attachment` excel文件名称(完整文件名称,例如:ceshi.xlsx) ```js import render from '@feidao/web/atom/nodejs/render/render'; // 指定下载文件名称 const url = 'http://192.168.40.196/flippedclass/print.xlsx?attachment=ceshi.xlsx'; // 文件名称无需制定,下载为本页面的名陈'print.xlsx' const url = 'http://192.168.40.196/flippedclass/print.xlsx'; // 渲染 render(fd.data.node, url, 'docx', 'p01'); ``` - 名称 - `jsreport-html-to-xlsx` - `jsreport-xlsx` - `inline-source` - `jsreport-core` ```安装 在package-service.json里的dependencies里添加` "jsreport-html-to-xlsx": "latest", "jsreport-xlsx": "latest", "inline-source": "latest", "jsreport-core": "latest" ` 在package.json里的devDependencies里添加` "jsreport-html-to-xlsx": "latest", "jsreport-xlsx": "latest", "inline-source": "latest", "jsreport-core": "latest" ` ``` ### 导出docx - 参数 - `attachment` docx文件名称(完整文件名称,例如:ceshi.docx) ```js import render from '@feidao/web/atom/nodejs/render/render'; // 指定下载文件名称 const url = 'http://192.168.40.196/flippedclass/print.docx?attachment=ceshi.docx'; // 文件名称无需制定,下载为本页面的名陈'print.docx' const url = 'http://192.168.40.196/flippedclass/print.docx'; // 渲染 render(fd.data.node, url, 'docx', 'p01'); ``` - 名称 - `inline-source` - `jsreport-core` - `jsreport-html-embedded-in-docx` ```安装 在package-service.json里的dependencies里添加` "inline-source": "latest", "jsreport-core": "latest", "jsreport-html-embedded-in-docx": "latest" ` 在package.json里的devDependencies里添加` "inline-source": "latest", "jsreport-core": "latest", "jsreport-html-embedded-in-docx": "latest" ` ``` ### 服务导出excel - 暂时使用的第三方库为`exceljs` - 服务完成后本地测试需配置 - 配置的文件为:feidao-server.json ```js { "URL": "@访问地址@", "METHOD": "get", "SERVICE": "dataservice.nodejs", "DATA": { "modelid": "custom::js_@文件路径+文件名@" } } ``` - 注意,配置`访问地址`不能和文件`feidao-server.json`中已有的地址重复 - 配置之后,重新启动服务,本地测试路径为:http://127.0.0.1:8889/@访问地址@ - 打包之后请求的地址为:'./@访问地址@' ```安装 在package-service.json里的dependencies里添加` "exceljs": "latest" ` 在package.json里的devDependencies里添加` "exceljs": "latest" ` ``` ### 服务导出doc - 暂时使用的第三方库为`docx` - 服务完成后本地测试需配置 - 配置的文件为:feidao-server.json ```js { "URL": "@访问地址@", "METHOD": "get", "SERVICE": "dataservice.nodejs", "DATA": { "modelid": "custom::js_@文件路径+文件名@" } } ``` - 注意,配置`访问地址`不能和文件`feidao-server.json`中已有的地址重复 - 配置之后,重新启动服务,本地测试路径为:http://127.0.0.1:8889/@访问地址@ - 打包之后请求的地址为:'./@访问地址@' ```安装 在package-service.json里的dependencies里添加` "docx": "latest" ` 在package.json里的devDependencies里添加` "docx": "latest" ` ``` ## 支付 ### 微信支付回调 在文件feidao-server.json中配置 ```js { "URL": "wx-payfinish", "METHOD": "post", "SERVICE": "dataservice.nodejs", "DATA": { "modelid": "custom::js_wx-payfinish-pro" } } ``` ```安装 在package-service.json里的dependencies里添加` "xml2js": "latest" ` 在package.json里的devDependencies里添加` "xml2js": "latest" ` ``` 并提供给项目经理微信支付回调地址:http://@ip+端口@/wx-payfinish 在NODEJS服务`wx-payfinish-pro`完成支付回调后的逻辑。 ### 微信支付宝二码合一支付 1. 生成支付二维码(参考src-web/wx-ali-pay页面) 2. 二维码路径服务`wx-ali-pay`,`service/src/wx-ali-pay.ts`服务,首先在`feidao-server.json`配置 ```ts { "URL": "wx-ali-pay", "METHOD": "get", "SERVICE": "dataservice.nodejs", "DATA": { "modelid": "custom::js_wx-ali-pay" } } ``` 3. 微信支付页面(参考src-web/wx-pay页面) ### 支付宝支付回调 在文件feidao-server.json中配置 ```js { "URL": "zfb-payfinish", "METHOD": "post", "SERVICE": "dataservice.nodejs", "DATA": { "modelid": "custom::js_zfb-payfinish-pro" } } ``` 并提供给项目经理微信支付回调地址:http://@ip+端口@/zfb-payfinish 在NODEJS服务`zfb-payfinish-pro`完成支付回调后的逻辑。 ### 银联支付回调 #### 银联支付后台回调 在文件feidao-server.json中配置 ```js { "URL": "union-payfinish", "METHOD": "post", "SERVICE": "dataservice.nodejs", "DATA": { "modelid": "custom::js_union-payfinish-pro" } } ``` 并提供给项目经理微信支付回调地址:http://@ip+端口@/union-payfinish 在NODEJS服务`union-payfinish-pro`完成支付回调后的逻辑。 #### 银联支付前台回调 **注意:银联支付前台回调,需支付者点击进入存在不可靠性,前台通知只能作为商户支付结果页的入口,最终支付结果必须以交易状态查询接口返回为准,不能仅依赖前台通知** [https://open.unionpay.com/tjweb/acproduct/list?apiservId=448&version=V2.2] 在文件feidao-server.json中配置 ```js { "URL": "union-payfinish-front", "METHOD": "post", "SERVICE": "dataservice.nodejs", "DATA": { "modelid": "custom::js_union-payfinish-front" } } ``` 并提供给项目经理微信支付回调地址:http://@ip+端口@/union-payfinish-front 在NODEJS服务`union-payfinish-front`完成支付回调后的逻辑。 ## 登录 ### web+h5 使用私有服务(java提供的接口,msgtype中含有项目spaceid的服务)进行登录时,必须在nodejs服务中执行登录(java接口)服务 代码示例为:/service/src/web-login.ts 并在`feidao-server.json`中配置服务 ```json { "URL": "login", "METHOD": "get", "SERVICE": "dataservice.nodejs", "DATA": { "modelid": "custom::js_web-login" } } ``` 在`config**.ts`中配置请求地址 ```ts export const login = `${server}/login`; ``` 在响应中调用登录 ```ts import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces'; import get from '@feidao/web/atom/browser/msg/get'; import { login } from '../../atom-web/config'; export default async function a001(fd: IFeidaoAiBrowserComponent, ...args: any[]) { // 获取用户名,密码,验证码 const user_name = ''; const password = ''; const captcha = ''; const param = { user_name, password, captcha }; // 调用登录服务 const res = await get(login, param); // 解析登录服务返回的结果 } ``` ### 微信小程序 在响应中调用私有服务(java提供的接口,msgtype中含有项目spaceid的服务)进行登录 ```ts import { IFeidaoAiWeappPage } from '@feidao/web/interfaces'; import call_service from '@feidao/web/atom/wx/app/msg/call-service'; import { send_msg as url, spaceid, productid } from '../atom-wx-app/config'; import set_storage_sync from '@feidao/web/atom/wx/app/api/cache/set-storage-sync'; export default async function a001(fd: IFeidaoAiWeappPage, ...args: any[]) { // 获取用户基本信息 const info3 = await call_service<{sessionid:string;}>(url, '', { flag: '102', phone: phoneno, spaceid, productid }); // 将sessionid保存到storage中 set_storage_sync('sessionid', 'sessionid=' + info3.sessionid + '; Path=/'); } ```