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)
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;

12
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,

1
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);
};

111
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
}
}

3
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",

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 { 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

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

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

Loading…
Cancel
Save