diff --git a/api/app/controller/user.js b/api/app/controller/user.js index 1356546..0d87ec6 100644 --- a/api/app/controller/user.js +++ b/api/app/controller/user.js @@ -6,6 +6,11 @@ class UserController extends Controller { console.log(777,ctx.request.body) ctx.body = await ctx.service.user.index(ctx.request.body) } + async download() { + const { ctx } = this; + console.log(777,ctx.request.body) + ctx.body = await ctx.service.user.downloadPng(ctx.request.body) + } } module.exports = UserController; diff --git a/api/app/model/user.js b/api/app/model/user.js index df40c47..8361f50 100644 --- a/api/app/model/user.js +++ b/api/app/model/user.js @@ -17,13 +17,13 @@ module.exports = app => { type: String, default: "", }, - phone: { - type: String, - default: "" + age: { + type: Number, + default: 20 }, - imgname: { - type: String, - default: "" + createImgList: { + type: Array, + default: [] }, imgbase64: { type: String, diff --git a/api/app/router.js b/api/app/router.js index b902cab..654b690 100644 --- a/api/app/router.js +++ b/api/app/router.js @@ -4,4 +4,5 @@ module.exports = app => { const { router, controller } = app; router.post('/api/upload', controller.user.index); + router.post('/api/download', controller.user.download); }; diff --git a/api/app/service/user.js b/api/app/service/user.js index 5791495..43029b0 100644 --- a/api/app/service/user.js +++ b/api/app/service/user.js @@ -2,64 +2,71 @@ const Service = require('egg').Service; const _ = require("lodash") +const tencentcloud = require('tencentcloud-sdk-nodejs'); +// 导入对应产品模块的client models。 +const CvmClient = tencentcloud.iotexplorer.v20190423.Client + class UserService extends Service { async index(params) { let { ctx } = this let modelLocal = ctx.model.User let returnData = { hasError: false, msg: "数据错误", list: [] } - //新增 - let subType = params.subType - let returnComponent = params.returnData || [] - let paramsLocal = _.omit(params, ["subType", "returnData"]) - if (subType === "add") { - paramsLocal["update_at"] = Date.now(); - let res = await modelLocal.create(paramsLocal) - returnData.hasError = false - returnData.msg = "数据新增成功" - returnData.list = res - } else if (subType === "multi") { - paramsLocal["update_at"] = Date.now(); - let res = await modelLocal.insertMany(paramsLocal.list) - returnData.hasError = false - returnData.msg = "数据新增成功" - returnData.list = res - } else if (subType === "del") { - let res = await modelLocal.updateMany({ _id: { $in: paramsLocal.ids } }, { isExit: 0, update_at: Date.now() }) - returnData.hasError = false - returnData.msg = "数据删除成功" - returnData.list = res - } else if (subType === "edit") { - paramsLocal["update_at"] = Date.now(); - let res = await modelLocal.updateOne({ _id: paramsLocal._id }, paramsLocal) - returnData.hasError = false - returnData.msg = "数据更新成功" - returnData.list = res - } else if (subType === "get") { - let pageSize = paramsLocal.pageSize - let currentPage = paramsLocal.currentPage - let paramsLocalInfo = _.omit(paramsLocal, ["pageSize", "currentPage"]) - let paramsLocalInfoNotDel = { ...paramsLocalInfo, isExit: 1 } - let res = await modelLocal.find(paramsLocalInfoNotDel).sort({ update_at: -1 }).skip((currentPage - 1) * pageSize).limit(pageSize) - let count = await modelLocal.find(paramsLocalInfoNotDel).count() - let resData = []; - for (let i = 0; i < res.length; i++) { - let elei = res[i]; - let resObj = { _id: elei._id } - if (returnComponent.length) { - for (let j = 0; j < returnComponent.length; j++) { - let elej = returnComponent[j]; - resObj[elej] = elei[elej] - } - } else { - resObj = elei - } - resData.push(resObj) - } - returnData.hasError = false - returnData.msg = "查询成功" - returnData.list = resData - returnData["count"] = count + console.log(77777, params) + // 新增 + paramsLocal["update_at"] = Date.now(); + let paramsLocal = { + name: params.name, + age: params.age, + imgbase64: params.img, + } + let pngRes=await this.createPng(params) + // let res = await modelLocal.create(paramsLocal) + returnData.hasError = false + returnData.msg = "数据新增成功" + returnData.list = res + return returnData + } + async createPng(params) { + let { ctx } = this + let modelLocal = ctx.model.User + let returnData = { hasError: false, msg: "数据错误", list: [] } + console.log(77777, params) + const client = new CvmClient({ + // 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中,请参考本文凭证管理章节。 + // 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。 + credential: { + secretId: process.env.TENCENTCLOUD_SECRET_ID, + secretKey: process.env.TENCENTCLOUD_SECRET_KEY, + }, + // 产品地域 + region: "ap-chengdu", + // 可选配置实例 + profile: { + signMethod: "TC3-HMAC-SHA256", // 签名方法 + httpProfile: { + reqMethod: "POST", // 请求方法 + reqTimeout: 30, // 请求超时时间,默认60s + }, + }, } + ); + const params = { + // 这里填写接口所需的参数,例如: + ImageUrl: params.img, // 图片URL + Age: params.age, // 想要改变的年龄,比如50表示变老50岁 + // 其他参数根据接口文档填充 + }; + + let res = client.ChangeFaceAge(params) + console.log(777, res) + return returnData + } + async downloadPng(params) { + let { ctx } = this + let modelLocal = ctx.model.User + let returnData = { hasError: false, msg: "数据错误", list: [] } + console.log(77777, params) + //查询后下载8张图片 return returnData } } diff --git a/api/package.json b/api/package.json index 846d5ba..b7c248f 100644 --- a/api/package.json +++ b/api/package.json @@ -11,7 +11,8 @@ "egg-mongoose": "^4.0.1", "egg-scripts": "2", "lodash": "^4.17.21", - "md5": "^2.3.0" + "md5": "^2.3.0", + "tencentcloud-sdk-nodejs": "^4.0.852" }, "devDependencies": { "egg-bin": "6", diff --git a/front/src/main/index.js b/front/src/main/index.js index 02e1af8..399af90 100644 --- a/front/src/main/index.js +++ b/front/src/main/index.js @@ -1,7 +1,7 @@ -import { app, shell, BrowserWindow, nativeImage } from 'electron' +import { app, shell, BrowserWindow, nativeImage,ipcMain } from 'electron' import * as path from 'path' import { electronApp, optimizer, is } from '@electron-toolkit/utils' - +import axios from 'axios' // logo const logoIcon = nativeImage.createFromPath(path.join(__dirname, '../../public/icon/icon.jpg')) console.log(process.versions.node) @@ -56,6 +56,9 @@ app.whenReady().then(() => { // dock icon is clicked and there are no other windows open. if (BrowserWindow.getAllWindows().length === 0) createWindow() }) + ipcMain.on('sendMessage', (eve, msg) => { + axios.post(`http://127.0.0.1:7001/api/upload`, msg) + }) }) // Quit when all windows are closed, except on macOS. There, it's common diff --git a/front/src/renderer/src/App.vue b/front/src/renderer/src/App.vue index 6f53345..1d1a81a 100644 --- a/front/src/renderer/src/App.vue +++ b/front/src/renderer/src/App.vue @@ -1,8 +1,7 @@