小程序发布
This commit is contained in:
28
src/rest/wechat/add.js
Normal file
28
src/rest/wechat/add.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
const dbUtils = require("../../utils/dbUitls");
|
||||||
|
module.exports = {
|
||||||
|
action: "/node/wxmp/addOrUpdate",
|
||||||
|
method: "post",
|
||||||
|
execute: (request, response) => {
|
||||||
|
let {appid, privateKey, projectPath, version, miniapp_appid} = request.body,
|
||||||
|
form = {appid, privateKey, projectPath, version}, sql
|
||||||
|
if (form.appid) {//编辑
|
||||||
|
let arr = Object.keys(form).filter(e => form[e]).map(e => `${e}='${form[e]}'`)
|
||||||
|
sql = `update node_wxmp_config set ${arr.join(",")} where appid='${form.appid}'`
|
||||||
|
} else {//新增
|
||||||
|
let cols = [], arr = []
|
||||||
|
form.appid = miniapp_appid
|
||||||
|
Object.keys(form).map(e => {
|
||||||
|
if (form[e]) {
|
||||||
|
cols.push(e)
|
||||||
|
arr.push(`'${form[e]}'`)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
sql = `insert into node_wxmp_config (${cols.join(",")}) values(${arr.join(",")})`
|
||||||
|
}
|
||||||
|
dbUtils.query(sql).then(() => {
|
||||||
|
response.send({code: 0})
|
||||||
|
}).catch(err => {
|
||||||
|
response.send({code: 1, err: err.sqlMessage})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
17
src/rest/wechat/confirmZip.js
Normal file
17
src/rest/wechat/confirmZip.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
const dbUtils = require("../../utils/dbUitls");
|
||||||
|
module.exports = {
|
||||||
|
action: "/node/wxmp/confirmZip",
|
||||||
|
method: "post",
|
||||||
|
execute: (request, response) => {
|
||||||
|
let id = request.query?.appid, sql = `select * from node_wxmp_config where appid='${id}'`
|
||||||
|
dbUtils.query(sql).then(res => {
|
||||||
|
let info = res?.[0]
|
||||||
|
if (info?.appid) {
|
||||||
|
response.send({code: 0, data: info})
|
||||||
|
} else response.send({code: 1, err: "无法找到小程序信息"})
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
response.send({code: 1, err: err.sqlMessage})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/rest/wechat/detail.js
Normal file
16
src/rest/wechat/detail.js
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
const dbUtils = require("../../utils/dbUitls");
|
||||||
|
module.exports = {
|
||||||
|
action: "/node/wxmp/detail",
|
||||||
|
method: "post",
|
||||||
|
execute: (request, response) => {
|
||||||
|
let {appid} = request.query
|
||||||
|
dbUtils.query(`select * from node_dvcp_config where appid='${appid}' limit 0,1`).then(res => {
|
||||||
|
response.send({
|
||||||
|
code: 0,
|
||||||
|
data: res?.[0]
|
||||||
|
})
|
||||||
|
}).catch(err => {
|
||||||
|
response.send({code: 1, err: err.sqlMessage})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
32
src/rest/wechat/getZip.js
Normal file
32
src/rest/wechat/getZip.js
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
const db = require("../../utils/dbUitls");
|
||||||
|
const execute = require("../../tools/exec")
|
||||||
|
const dayjs = require("dayjs")
|
||||||
|
const fse = require("fs-extra");
|
||||||
|
module.exports = {
|
||||||
|
action: "/node/wxmp/getZip",
|
||||||
|
method: "post",
|
||||||
|
execute: (request, response) => {
|
||||||
|
let id = request.query?.appid, sql = `select * from node_dvcp_config where appid='${id}'`
|
||||||
|
db.query(sql).then(res => {
|
||||||
|
let info = res?.[0]
|
||||||
|
if (info?.appid) {
|
||||||
|
db.query(`update node_wxmp_config set error=null where appid='${info.appid}'`).then(() => setTimeout(() => {
|
||||||
|
response.send({code: 0})
|
||||||
|
}, 2000))
|
||||||
|
execute(`cd /root/node-service/dvcp_v2_wechat&&node bin/pages.js ${id}&&npm run build`)
|
||||||
|
.then(() => fse.emptyDir(`../wxmpZips/${id}/`))
|
||||||
|
.then(() => fse.copy('../dvcp_v2_wechat/dist/build/mp-weixin/', `../wxmpZips/${id}/`))
|
||||||
|
.then(() => fse.emptyDir('../dvcp_v2_wechat/dist/build'))
|
||||||
|
.then(() => {
|
||||||
|
db.query(`update node_wxmp_config set error='打包时间:${dayjs().format("YYYY-MM-DD HH:mm:ss")}' where appid='${info.appid}'`)
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
db.query(`update node_wxmp_config set error='${err}' where appid='${info.appid}'`)
|
||||||
|
})
|
||||||
|
} else response.send({code: 1, err: "无法找到小程序信息"})
|
||||||
|
}).catch(err => {
|
||||||
|
console.log(err)
|
||||||
|
response.send({code: 1, err: err.sqlMessage})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
28
src/rest/wechat/list.js
Normal file
28
src/rest/wechat/list.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
const dbUtils = require("../../utils/dbUitls");
|
||||||
|
module.exports = {
|
||||||
|
action: "/node/wxmp/list",
|
||||||
|
method: "post",
|
||||||
|
execute: (request, response) => {
|
||||||
|
let total = 0, records = [], {size, current, name} = request.query
|
||||||
|
Promise.all([
|
||||||
|
dbUtils.query(`select 1 from node_dvcp_config`).then(res => {
|
||||||
|
return total = res.length
|
||||||
|
}),
|
||||||
|
new Promise(resolve => {
|
||||||
|
let sql = `select * from node_dvcp_config where name like '%${name}%' limit ${(current-1)*size},${size}`
|
||||||
|
dbUtils.query(sql).then(res => {
|
||||||
|
records = res
|
||||||
|
resolve()
|
||||||
|
}).catch(err => {
|
||||||
|
response.send({code: 1, err: err.sqlMessage})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
]).then(() => {
|
||||||
|
response.send({
|
||||||
|
code: 0,
|
||||||
|
data: {records, total}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user