Browse Source

update

master
lc18518571399 11 months ago
parent
commit
871db87097
  1. 5
      api/app/controller/user.js
  2. 12
      api/app/model/user.js
  3. 1
      api/app/router.js
  4. 111
      api/app/service/user.js
  5. 3
      api/package.json
  6. 7
      front/src/main/index.js
  7. 88
      front/src/renderer/src/App.vue

5
api/app/controller/user.js

@ -6,6 +6,11 @@ class UserController extends Controller {
console.log(777,ctx.request.body) console.log(777,ctx.request.body)
ctx.body = await ctx.service.user.index(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; module.exports = UserController;

12
api/app/model/user.js

@ -17,13 +17,13 @@ module.exports = app => {
type: String, type: String,
default: "", default: "",
}, },
phone: { age: {
type: String, type: Number,
default: "" default: 20
}, },
imgname: { createImgList: {
type: String, type: Array,
default: "" default: []
}, },
imgbase64: { imgbase64: {
type: String, type: String,

1
api/app/router.js

@ -4,4 +4,5 @@
module.exports = app => { module.exports = app => {
const { router, controller } = app; const { router, controller } = app;
router.post('/api/upload', controller.user.index); router.post('/api/upload', controller.user.index);
router.post('/api/download', controller.user.download);
}; };

111
api/app/service/user.js

@ -2,64 +2,71 @@
const Service = require('egg').Service; const Service = require('egg').Service;
const _ = require("lodash") const _ = require("lodash")
const tencentcloud = require('tencentcloud-sdk-nodejs');
// 导入对应产品模块的client models。
const CvmClient = tencentcloud.iotexplorer.v20190423.Client
class UserService extends Service { class UserService extends Service {
async index(params) { async index(params) {
let { ctx } = this let { ctx } = this
let modelLocal = ctx.model.User let modelLocal = ctx.model.User
let returnData = { hasError: false, msg: "数据错误", list: [] } let returnData = { hasError: false, msg: "数据错误", list: [] }
//新增 console.log(77777, params)
let subType = params.subType // 新增
let returnComponent = params.returnData || [] paramsLocal["update_at"] = Date.now();
let paramsLocal = _.omit(params, ["subType", "returnData"]) let paramsLocal = {
if (subType === "add") { name: params.name,
paramsLocal["update_at"] = Date.now(); age: params.age,
let res = await modelLocal.create(paramsLocal) imgbase64: params.img,
returnData.hasError = false }
returnData.msg = "数据新增成功" let pngRes=await this.createPng(params)
returnData.list = res // let res = await modelLocal.create(paramsLocal)
} else if (subType === "multi") { returnData.hasError = false
paramsLocal["update_at"] = Date.now(); returnData.msg = "数据新增成功"
let res = await modelLocal.insertMany(paramsLocal.list) returnData.list = res
returnData.hasError = false return returnData
returnData.msg = "数据新增成功" }
returnData.list = res async createPng(params) {
} else if (subType === "del") { let { ctx } = this
let res = await modelLocal.updateMany({ _id: { $in: paramsLocal.ids } }, { isExit: 0, update_at: Date.now() }) let modelLocal = ctx.model.User
returnData.hasError = false let returnData = { hasError: false, msg: "数据错误", list: [] }
returnData.msg = "数据删除成功" console.log(77777, params)
returnData.list = res const client = new CvmClient({
} else if (subType === "edit") { // 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中,请参考本文凭证管理章节。
paramsLocal["update_at"] = Date.now(); // 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。
let res = await modelLocal.updateOne({ _id: paramsLocal._id }, paramsLocal) credential: {
returnData.hasError = false secretId: process.env.TENCENTCLOUD_SECRET_ID,
returnData.msg = "数据更新成功" secretKey: process.env.TENCENTCLOUD_SECRET_KEY,
returnData.list = res },
} else if (subType === "get") { // 产品地域
let pageSize = paramsLocal.pageSize region: "ap-chengdu",
let currentPage = paramsLocal.currentPage // 可选配置实例
let paramsLocalInfo = _.omit(paramsLocal, ["pageSize", "currentPage"]) profile: {
let paramsLocalInfoNotDel = { ...paramsLocalInfo, isExit: 1 } signMethod: "TC3-HMAC-SHA256", // 签名方法
let res = await modelLocal.find(paramsLocalInfoNotDel).sort({ update_at: -1 }).skip((currentPage - 1) * pageSize).limit(pageSize) httpProfile: {
let count = await modelLocal.find(paramsLocalInfoNotDel).count() reqMethod: "POST", // 请求方法
let resData = []; reqTimeout: 30, // 请求超时时间,默认60s
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
} }
);
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 return returnData
} }
} }

3
api/package.json

@ -11,7 +11,8 @@
"egg-mongoose": "^4.0.1", "egg-mongoose": "^4.0.1",
"egg-scripts": "2", "egg-scripts": "2",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"md5": "^2.3.0" "md5": "^2.3.0",
"tencentcloud-sdk-nodejs": "^4.0.852"
}, },
"devDependencies": { "devDependencies": {
"egg-bin": "6", "egg-bin": "6",

7
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 * as path from 'path'
import { electronApp, optimizer, is } from '@electron-toolkit/utils' import { electronApp, optimizer, is } from '@electron-toolkit/utils'
import axios from 'axios'
// logo // logo
const logoIcon = nativeImage.createFromPath(path.join(__dirname, '../../public/icon/icon.jpg')) const logoIcon = nativeImage.createFromPath(path.join(__dirname, '../../public/icon/icon.jpg'))
console.log(process.versions.node) console.log(process.versions.node)
@ -56,6 +56,9 @@ app.whenReady().then(() => {
// dock icon is clicked and there are no other windows open. // dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow() 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 // Quit when all windows are closed, except on macOS. There, it's common

88
front/src/renderer/src/App.vue

@ -1,8 +1,7 @@
<template> <template>
<div class="appClass" v-if="isVip"> <div class="appClass" v-if="isVip">
<dv-border-box1 ref="borderRef" style="text-align: center;width: 100vw;height: 100vh;"> <dv-border-box1 ref="borderRef" style="text-align: center; width: 100vw; height: 100vh">
<dv-button style="width: 90%;margin-left: 5%;">米微婚礼</dv-button> <dv-button style="width: 90%; margin-left: 5%">米微婚礼</dv-button>
<div class="topinput"> <div class="topinput">
<dv-border-box8 :dur="5" class="topinputinfo"> <dv-border-box8 :dur="5" class="topinputinfo">
<div dv-bg> <div dv-bg>
@ -62,9 +61,9 @@ export default {
return { return {
_: _, _: _,
form: { form: {
name: "", name: '',
age: null, age: null,
img: "" img: ''
}, },
videoEL: null, videoEL: null,
isVip: false isVip: false
@ -72,64 +71,72 @@ export default {
}, },
methods: { methods: {
async takePhotoUpload() { async takePhotoUpload() {
this.form.img = "" this.form.img = ''
let device = ''; // deviceId let device = '' // deviceId
this.dialogTakePhotoShow = true; this.dialogTakePhotoShow = true
let stream = navigator.mediaDevices.enumerateDevices() let stream = navigator.mediaDevices
.then(devices => { //id使 .enumerateDevices()
.then((devices) => {
//id使
for (let i in devices) { for (let i in devices) {
if (devices[i].kind == 'videoinput') { if (devices[i].kind == 'videoinput') {
device = devices[i]; device = devices[i]
break; break
} }
} }
}) })
.then(() => { .then(() => {
navigator.mediaDevices.getUserMedia({ navigator.mediaDevices
audio: false, .getUserMedia({
video: { audio: false,
sourceId: device.deviceId, // ID video: {
width: 500, sourceId: device.deviceId, // ID
height: 450 width: 500,
// height: 450
// width:{min: 1000, ideal: 1000, max: 3264 }, //
// height:{min: 1080, ideal: 1080, max: 2488} // width:{min: 1000, ideal: 1000, max: 3264 },
} // height:{min: 1080, ideal: 1080, max: 2488}
}).then(success => { }
// })
this.$refs['videoEL'].srcObject = success; .then((success) => {
// //
this.$refs['videoEL'].play(); this.$refs['videoEL'].srcObject = success
}) //
.catch(error => { this.$refs['videoEL'].play()
})
.catch((error) => {
console.error('摄像头开启失败,请检查摄像头是否可用!') console.error('摄像头开启失败,请检查摄像头是否可用!')
}) })
}) })
}, },
async takePhoto() { async takePhoto() {
let ctx = this.$refs['canvas'].getContext('2d'); let ctx = this.$refs['canvas'].getContext('2d')
// canvas // canvas
ctx.drawImage(this.$refs['videoEL'], 0, 0); ctx.drawImage(this.$refs['videoEL'], 0, 0)
// base64 // base64
this.form.img = this.$refs['canvas'].toDataURL('image/png', 0.7); // KB this.form.img = this.$refs['canvas'].toDataURL('image/png', 0.2) // KB
if (!this.$refs['videoEL'].srcObject) return; if (!this.$refs['videoEL'].srcObject) return
let stream = this.$refs['videoEL'].srcObject; let stream = this.$refs['videoEL'].srcObject
let tracks = stream.getTracks(); let tracks = stream.getTracks()
tracks.forEach(track => { tracks.forEach((track) => {
track.stop(); track.stop()
}) })
this.$refs['videoEL'].srcObject = null; this.$refs['videoEL'].srcObject = null
console.log(777, this.form.img) console.log(777, this.form.img)
}, },
async updateSeach() { async updateSeach() {
console.log(7777, this.form) console.log(7777, this.form)
let res = await this.$axios.post('/api/upload', {
window.electron.ipcRenderer.send('sendMessage', {
name: this.form.name, name: this.form.name,
age: this.form.age, age: this.form.age,
img: this.form.img img: this.form.img
}) })
ElMessage({
message: '上传成功',
type: 'success'
})
} }
}, },
async mounted() { async mounted() {
let fiveDay = dayjs('2024-05-16T00:00:00').valueOf() let fiveDay = dayjs('2024-05-16T00:00:00').valueOf()
@ -163,7 +170,6 @@ export default {
height: 45px; height: 45px;
width: 360px; width: 360px;
margin: 12px 0; margin: 12px 0;
} }
.botimg { .botimg {

Loading…
Cancel
Save