Commit da0ac451 authored by wanli's avatar wanli

🐞 fix(应用编辑模块): 修复应用编辑后端接口bug

前端增加应用编辑功能
parent 35c6ad51
......@@ -232,7 +232,7 @@ class AppResource(object):
return True, ResponseCode.HTTP_SUCCESS
def put(self, uuid, params, jwt={}):
user = UserModel.query.filter(UserModel.id==params.get('user')).one_or_none()
user = UserModel.query.filter(UserModel.uuid==jwt.get('uuid')).one_or_none()
if not user:
return False, ResponseCode.USER_NOT_EXISTS
......@@ -245,15 +245,15 @@ class AppResource(object):
# 更新文件
if params.get("app_files"):
for a in params.get("app_files"):
res = AnnexModel(app=app, title=a.get("filename"), path=a.get("filepath"), size=a.get("filesize"), create_by=user, create_at=datetime.now(), update_by=user, update_at=datetime.now())
res = AnnexModel(app=app.id, title=a.get("filename"), path=a.get("filepath"), size=a.get("filesize"), create_by=user.id, create_at=datetime.now(), update_by=user.id, update_at=datetime.now())
db.session.add(res)
db.session.flush()
db.session.commit()
params.pop("app_files")
# 更新icon
if params.get("app_icon"):
condition = { 'update_by': user, 'update_at': datetime.now() }
if params.get("app_icon") and isinstance(params.get("app_icon"), dict):
condition = { 'update_by': user.id, 'update_at': datetime.now() }
if params.get("app_icon").get("filename"):
condition.update({"title": params.get("app_icon").get("filename")})
if params.get("app_icon").get("filepath"):
......@@ -266,7 +266,7 @@ class AppResource(object):
for key, value in params.items():
if value != None:
setattr(app, key, value)
app.update_by = jwt.get("id", "")
app.update_by = user.id
app.update_date = datetime.now()
db.session.commit()
return True, ResponseCode.HTTP_SUCCESS
......
......@@ -113,6 +113,7 @@ class GetListAppSchema(ma.SQLAlchemySchema):
app_name = fields.String(required=False, nullable=True)
app_icon = fields.String(required=False, nullable=True)
app_version = fields.String(required=False, nullable=True)
algorithm = fields.String(required=False, nullable=True)
category = fields.String(required=False, nullable=True)
launcher = fields.String(required=False, nullable=True)
app_arch = fields.String(required=False, nullable=True)
......@@ -123,7 +124,7 @@ class GetListAppSchema(ma.SQLAlchemySchema):
app_review = fields.Integer(required=False, nullable=True)
create_at = fields.DateTime(required=False, nullable=True)
update_at = fields.DateTime(required=False, nullable=True)
remarks = fields.String(required=False)
getListAppSchema = GetListAppSchema()
getListAppsSchema = GetListAppSchema(many=True)
......@@ -153,13 +154,17 @@ class PutAppSchema(ma.SQLAlchemySchema):
unknown = EXCLUDE # 未知字段默认排除
model = AppModel
app_name = ma.auto_field()
app_icon = ma.auto_field()
app_version = ma.auto_field()
app_screen_size = ma.auto_field()
app_arch = ma.auto_field()
app_review = ma.auto_field()
category = ma.auto_field()
launcher = ma.auto_field()
app_name = fields.String(required=False, nullable=True)
app_icon = fields.String(required=False, nullable=True)
app_version = fields.String(required=False, nullable=True)
category = fields.String(required=False, nullable=True)
launcher = fields.String(required=False, nullable=True)
app_arch = fields.String(required=False, nullable=True)
download_url = fields.String(required=False, nullable=True)
app_file_size = fields.Integer(required=False, nullable=True)
app_screen_size = fields.String(required=False, nullable=True)
meta_data = fields.String(required=False, nullable=True)
app_review = fields.Integer(required=False, nullable=True)
remarks = fields.String(required=False, nullable=True)
putAppSchema = PutAppSchema()
......@@ -151,14 +151,15 @@ class AppResource(Resource):
@jwt_required(locations=["headers"])
def put(self, uuid):
try:
jwt = get_jwt_identity()
json_payload = request.json
print("========>", uuid, json_payload)
data = putAppSchema.load(json_payload)
result, message = signalManager.actionPutApp.emit(uuid, data)
result, message = signalManager.actionPutApp.emit(uuid, data, jwt)
if result:
return response_result(ResponseCode.HTTP_SUCCESS, data=result)
return response_result(message)
except Exception as e:
traceback.print_exc()
current_app.logger.error(e)
return response_result(ResponseCode.HTTP_SERVER_ERROR)
......
/*
* @Author: your name
* @Date: 2021-07-15 09:33:39
* @LastEditTime: 2021-07-20 01:59:15
* @LastEditTime: 2021-07-20 14:53:11
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \evm-store\tools\frontend\src\api\openapi.js
......@@ -39,6 +39,14 @@ export function postLogin(params) {
});
}
export function updateApplication(uuid, params) {
return request({
url: `/api/v1/app/${uuid}`,
method: "put",
data: params,
});
}
export function postApplication(params) {
return request({
url: "/api/v1/app",
......
......@@ -185,6 +185,7 @@ const router = new Router({
},
{
path: "/application/form",
name: "ApplicationForm",
component: () => import("@/views/Application/Form"),
},
{
......
......@@ -132,8 +132,8 @@
style="margin-top: 24px"
:wrapperCol="{ span: 10, offset: 7 }"
>
<a-button type="primary" @click="onSumbit">提交</a-button>
<a-button style="margin-left: 8px">保存</a-button>
<a-button type="primary" v-if="title == '添加'" @click="onSumbit">提交</a-button>
<a-button style="margin-left: 8px" v-else @click="updateApplication">保存</a-button>
</a-form-item>
</a-form>
</a-card>
......@@ -165,15 +165,16 @@ import {
import PageHeaderWrapper from "@/components/PageHeaderWrapper";
import DescriptionItem from "@/components/DescriptionItem";
import { postApplication } from "@/api/openapi";
import { mapTrim } from "@/utils/index";
import { postApplication, updateApplication } from "@/api/openapi";
export default {
name: "BasicForm",
name: "ApplicationForm",
data() {
return {
loading: false,
imageUrl: "",
value: 1,
uuid: null,
title: "添加",
post: {
app_name: null,
......@@ -281,6 +282,13 @@ export default {
this.postApplication(formData)
},
updateApplication() {
updateApplication(this.uuid, mapTrim(this.post)).then(res => {
message.success(res.msg)
}).catch(err => {
message.error(err.msg)
})
},
postApplication(formData) {
postApplication(formData).then(res => {
// this.fileList = [];
......@@ -304,11 +312,14 @@ export default {
},
},
created() {
const { type } = this.$route.query
if (type && type == "update") {
this.title = "更新"
} else {
this.title = "添加"
const params = this.$route.params
console.log(params)
if (params.title) {
this.title = params.title
}
if(params.record) {
this.uuid = params.record.uuid
this.post = params.record
}
},
};
......
......@@ -283,6 +283,8 @@
</a-row>
</template>
<template slot="action" slot-scope="text, record">
<a href="javascript:;" @click="handleEdit(record)">编辑应用</a>
<a-divider type="vertical" />
<a href="javascript:;" @click="rebuildApplication(record)"
>重新打包</a
>
......@@ -457,8 +459,10 @@ export default {
this.form = this.$form.createForm(this, {});
},
methods: {
handleEdit(record) {
this.$router.push({ name: "ApplicationForm", params: { title: "编辑", record: record } })
},
handleEditSource(record) {
console.log(record)
this.$router.push({ name: "FileManager", params: { directory: record.file_dir, disk: "epks" } })
},
updateReview(record, value) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment