对于采购件的内容进行修改,使其填写更加便利加上库位自动加载上一次的逻辑
This commit is contained in:
@ -5,19 +5,29 @@ import traceback
|
|||||||
|
|
||||||
inbound_buy_bp = Blueprint('stock_buy', __name__)
|
inbound_buy_bp = Blueprint('stock_buy', __name__)
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 0. 基础物料搜索
|
# 0. 基础物料搜索
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@inbound_buy_bp.route('/search-base', methods=['GET'])
|
@inbound_buy_bp.route('/search-base', methods=['GET'])
|
||||||
def search_base():
|
def search_base():
|
||||||
|
"""
|
||||||
|
供前端下拉框远程搜索使用
|
||||||
|
Query Param: keyword (名称或规格)
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
keyword = request.args.get('keyword', '')
|
keyword = request.args.get('keyword', '')
|
||||||
data = BuyInboundService.search_base_material(keyword)
|
data = BuyInboundService.search_base_material(keyword)
|
||||||
return jsonify({"code": 200, "msg": "success", "data": data})
|
return jsonify({
|
||||||
|
"code": 200,
|
||||||
|
"msg": "success",
|
||||||
|
"data": data
|
||||||
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 1. 获取列表
|
# 1. 获取列表
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@ -27,6 +37,8 @@ def get_list():
|
|||||||
page = request.args.get('page', 1, type=int)
|
page = request.args.get('page', 1, type=int)
|
||||||
limit = request.args.get('pageSize', 15, type=int)
|
limit = request.args.get('pageSize', 15, type=int)
|
||||||
keyword = request.args.get('keyword', '')
|
keyword = request.args.get('keyword', '')
|
||||||
|
|
||||||
|
# 获取状态列表参数,前端传参格式: statuses=在库,借库
|
||||||
statuses_str = request.args.get('statuses', '')
|
statuses_str = request.args.get('statuses', '')
|
||||||
statuses = statuses_str.split(',') if statuses_str else []
|
statuses = statuses_str.split(',') if statuses_str else []
|
||||||
|
|
||||||
@ -36,6 +48,7 @@ def get_list():
|
|||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 2. 新增入库
|
# 2. 新增入库
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@ -45,12 +58,19 @@ def submit():
|
|||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
if not data:
|
if not data:
|
||||||
return jsonify({"code": 400, "msg": "No data"}), 400
|
return jsonify({"code": 400, "msg": "No data"}), 400
|
||||||
|
|
||||||
new_stock = BuyInboundService.handle_inbound(data)
|
new_stock = BuyInboundService.handle_inbound(data)
|
||||||
return jsonify({"code": 200, "msg": "入库成功", "data": new_stock.to_dict()})
|
|
||||||
|
return jsonify({
|
||||||
|
"code": 200,
|
||||||
|
"msg": "入库成功",
|
||||||
|
"data": new_stock.to_dict()
|
||||||
|
})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 3. 更新入库
|
# 3. 更新入库
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@ -63,6 +83,7 @@ def update_buy(id):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 4. 删除
|
# 4. 删除
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@ -74,8 +95,18 @@ def delete_buy(id):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
return jsonify({"code": 500, "msg": str(e)}), 500
|
return jsonify({"code": 500, "msg": str(e)}), 500
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 5. 供应商建议 (基于 base_id)
|
# 5. 获取关联的出库历史 (如果有)
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
@inbound_buy_bp.route('/<int:id>/history', methods=['GET'])
|
||||||
|
def get_history(id):
|
||||||
|
# 如果没有出库模块,这个接口可能为空,但为保持兼容性保留
|
||||||
|
return jsonify({"code": 200, "msg": "success", "data": []})
|
||||||
|
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 6. 供应商建议
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@inbound_buy_bp.route('/suggestions/suppliers', methods=['GET'])
|
@inbound_buy_bp.route('/suggestions/suppliers', methods=['GET'])
|
||||||
def get_supplier_suggestions():
|
def get_supplier_suggestions():
|
||||||
@ -85,8 +116,9 @@ def get_supplier_suggestions():
|
|||||||
data = BuyInboundService.get_history_suppliers(base_id)
|
data = BuyInboundService.get_history_suppliers(base_id)
|
||||||
return jsonify({"code": 200, "msg": "success", "data": data})
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 6. 采购人建议 (全局,基于 stock_buy 表)
|
# 7. 采购人建议 (全局)
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@inbound_buy_bp.route('/suggestions/users', methods=['GET'])
|
@inbound_buy_bp.route('/suggestions/users', methods=['GET'])
|
||||||
def get_user_suggestions():
|
def get_user_suggestions():
|
||||||
@ -95,7 +127,7 @@ def get_user_suggestions():
|
|||||||
return jsonify({"code": 200, "msg": "success", "data": data})
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
# 7. 链接建议 (基于 base_id)
|
# 8. 链接建议
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
@inbound_buy_bp.route('/suggestions/links', methods=['GET'])
|
@inbound_buy_bp.route('/suggestions/links', methods=['GET'])
|
||||||
def get_link_suggestions():
|
def get_link_suggestions():
|
||||||
@ -105,3 +137,14 @@ def get_link_suggestions():
|
|||||||
return jsonify({"code": 400, "msg": "base_id required"}), 400
|
return jsonify({"code": 400, "msg": "base_id required"}), 400
|
||||||
data = BuyInboundService.get_history_links(base_id, link_type)
|
data = BuyInboundService.get_history_links(base_id, link_type)
|
||||||
return jsonify({"code": 200, "msg": "success", "data": data})
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
# 9. [新增] 库位建议
|
||||||
|
# ------------------------------------------------------------------
|
||||||
|
@inbound_buy_bp.route('/suggestions/locations', methods=['GET'])
|
||||||
|
def get_location_suggestions():
|
||||||
|
base_id = request.args.get('base_id', type=int)
|
||||||
|
if not base_id:
|
||||||
|
return jsonify({"code": 400, "msg": "base_id required"}), 400
|
||||||
|
data = BuyInboundService.get_history_locations(base_id)
|
||||||
|
return jsonify({"code": 200, "msg": "success", "data": data})
|
||||||
@ -51,7 +51,8 @@ class BuyInboundService:
|
|||||||
query = query.filter(
|
query = query.filter(
|
||||||
or_(
|
or_(
|
||||||
MaterialBase.name.ilike(f'%{keyword}%'),
|
MaterialBase.name.ilike(f'%{keyword}%'),
|
||||||
MaterialBase.spec_model.ilike(f'%{keyword}%')
|
MaterialBase.spec_model.ilike(f'%{keyword}%'),
|
||||||
|
MaterialBase.pinyin.ilike(f'%{keyword}%')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
query = query.order_by(MaterialBase.id.desc()).limit(20)
|
query = query.order_by(MaterialBase.id.desc()).limit(20)
|
||||||
@ -336,22 +337,20 @@ class BuyInboundService:
|
|||||||
# ============================================================
|
# ============================================================
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_history_suppliers(base_id):
|
def get_history_suppliers(base_id):
|
||||||
"""返回该物料在 stock_buy 表中关联过的供应商列表"""
|
"""返回该物料关联的供应商列表(去重)"""
|
||||||
try:
|
try:
|
||||||
# 去重查询
|
|
||||||
query = db.session.query(StockBuy.supplier_name).filter(
|
query = db.session.query(StockBuy.supplier_name).filter(
|
||||||
StockBuy.base_id == base_id,
|
StockBuy.base_id == base_id,
|
||||||
StockBuy.supplier_name.isnot(None),
|
StockBuy.supplier_name.isnot(None),
|
||||||
StockBuy.supplier_name != ''
|
StockBuy.supplier_name != ''
|
||||||
).distinct().order_by(StockBuy.supplier_name)
|
).distinct().order_by(StockBuy.supplier_name)
|
||||||
|
|
||||||
suppliers = [row[0] for row in query.all()]
|
suppliers = [row[0] for row in query.all()]
|
||||||
return suppliers
|
return suppliers
|
||||||
except Exception:
|
except Exception:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# 7. 采购人/邮箱历史查询 (全局,从 stock_buy 获取)
|
# 7. 采购人建议 (全局,基于 stock_buy 表)
|
||||||
# ============================================================
|
# ============================================================
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_history_purchasers(keyword):
|
def get_history_purchasers(keyword):
|
||||||
@ -371,7 +370,7 @@ class BuyInboundService:
|
|||||||
StockBuy.buyer_email.ilike(kw)
|
StockBuy.buyer_email.ilike(kw)
|
||||||
))
|
))
|
||||||
|
|
||||||
# 按名字去重,取最新的记录(这里简单做 distinct,具体业务如果一个人有多个邮箱可能需要更复杂逻辑,这里简化为 distinct 组合)
|
# 按名字去重,取最新的记录(这里简单做 distinct)
|
||||||
results = query.distinct().limit(20).all()
|
results = query.distinct().limit(20).all()
|
||||||
|
|
||||||
users = []
|
users = []
|
||||||
@ -403,3 +402,22 @@ class BuyInboundService:
|
|||||||
return links
|
return links
|
||||||
except Exception:
|
except Exception:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
# ============================================================
|
||||||
|
# 9. [新增] 库位建议 (基于 base_id)
|
||||||
|
# ============================================================
|
||||||
|
@staticmethod
|
||||||
|
def get_history_locations(base_id):
|
||||||
|
"""查询该物料的历史存放库位,方便复用"""
|
||||||
|
try:
|
||||||
|
query = db.session.query(StockBuy.warehouse_location).filter(
|
||||||
|
StockBuy.base_id == base_id,
|
||||||
|
StockBuy.warehouse_location.isnot(None),
|
||||||
|
StockBuy.warehouse_location != ''
|
||||||
|
).distinct().limit(10)
|
||||||
|
|
||||||
|
# 简单去重列表
|
||||||
|
locs = [row[0] for row in query.all()]
|
||||||
|
return locs
|
||||||
|
except Exception:
|
||||||
|
return []
|
||||||
@ -47,17 +47,17 @@ export function searchMaterialBase(keyword: string) {
|
|||||||
// 6. 文件上传 (用于图片/拍照)
|
// 6. 文件上传 (用于图片/拍照)
|
||||||
export function uploadFile(data: FormData) {
|
export function uploadFile(data: FormData) {
|
||||||
return request({
|
return request({
|
||||||
url: '/common/upload',
|
url: '/common/upload', // 对应后端 /api/v1/common/upload
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data,
|
data,
|
||||||
headers: { 'Content-Type': 'multipart/form-data' }
|
headers: { 'Content-Type': 'multipart/form-data' }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// 7. 文件删除
|
// 7. [新增] 文件删除
|
||||||
export function deleteFile(filename: string) {
|
export function deleteFile(filename: string) {
|
||||||
return request({
|
return request({
|
||||||
url: `/common/files/${filename}`,
|
url: `/common/files/${filename}`, // 对应后端 /api/v1/common/files/<filename>
|
||||||
method: 'delete'
|
method: 'delete'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -88,3 +88,12 @@ export function getLinkSuggestions(params: any) {
|
|||||||
params
|
params
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 11. [新增] 库位建议
|
||||||
|
export function getLocationSuggestions(params: any) {
|
||||||
|
return request({
|
||||||
|
url: '/inbound/buy/suggestions/locations',
|
||||||
|
method: 'get',
|
||||||
|
params
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -98,6 +98,13 @@
|
|||||||
</el-tag>
|
</el-tag>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template #default="scope" v-else-if="col.prop === 'qty_stock'">
|
||||||
|
<span class="stock-num">{{ scope.row.qty_stock }}</span>
|
||||||
|
</template>
|
||||||
|
<template #default="scope" v-else-if="col.prop === 'qty_available'">
|
||||||
|
<span class="avail-num">{{ scope.row.qty_available }}</span>
|
||||||
|
</template>
|
||||||
|
|
||||||
<template #default="scope" v-else-if="['arrival_photo', 'inspection_report'].includes(col.prop)">
|
<template #default="scope" v-else-if="['arrival_photo', 'inspection_report'].includes(col.prop)">
|
||||||
<div v-if="getImagesOnly(scope.row[col.prop]).length > 0" style="display: flex; align-items: center; justify-content: center;">
|
<div v-if="getImagesOnly(scope.row[col.prop]).length > 0" style="display: flex; align-items: center; justify-content: center;">
|
||||||
<el-image
|
<el-image
|
||||||
@ -245,7 +252,18 @@
|
|||||||
<el-form-item label="条码" prop="barcode"><el-input v-model="form.barcode" placeholder="扫描条码"/></el-form-item>
|
<el-form-item label="条码" prop="barcode"><el-input v-model="form.barcode" placeholder="扫描条码"/></el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="6">
|
<el-col :span="6">
|
||||||
<el-form-item label="库位" prop="warehouse_location"><el-input v-model="form.warehouse_location" placeholder="例如: A-01-02"/></el-form-item>
|
<el-form-item label="库位" prop="warehouse_location">
|
||||||
|
<el-autocomplete
|
||||||
|
v-model="form.warehouse_location"
|
||||||
|
:fetch-suggestions="querySearchLocation"
|
||||||
|
placeholder="例如: A-01-02"
|
||||||
|
style="width: 100%"
|
||||||
|
clearable
|
||||||
|
:trigger-on-focus="true"
|
||||||
|
>
|
||||||
|
<template #default="{ item }"><div style="font-weight: 500">{{ item.value }}</div></template>
|
||||||
|
</el-autocomplete>
|
||||||
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
@ -487,7 +505,8 @@ import {
|
|||||||
deleteFile,
|
deleteFile,
|
||||||
getSupplierSuggestions,
|
getSupplierSuggestions,
|
||||||
getUserSuggestions,
|
getUserSuggestions,
|
||||||
getLinkSuggestions
|
getLinkSuggestions,
|
||||||
|
getLocationSuggestions
|
||||||
} from '@/api/inbound/buy'
|
} from '@/api/inbound/buy'
|
||||||
import {getLabelPreview, executePrint} from '@/api/common/print'
|
import {getLabelPreview, executePrint} from '@/api/common/print'
|
||||||
import WebRtcCamera from '@/components/Camera/WebRtcCamera.vue'
|
import WebRtcCamera from '@/components/Camera/WebRtcCamera.vue'
|
||||||
@ -617,7 +636,6 @@ const fetchUserSuggestions = async (query: string, cb: any) => {
|
|||||||
try {
|
try {
|
||||||
const res: any = await getUserSuggestions({ keyword: query })
|
const res: any = await getUserSuggestions({ keyword: query })
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
// res.data = [{value: '张三', email: 'xx@xx.com'}]
|
|
||||||
cb(res.data)
|
cb(res.data)
|
||||||
} else {
|
} else {
|
||||||
cb([])
|
cb([])
|
||||||
@ -629,7 +647,6 @@ const fetchUserSuggestions = async (query: string, cb: any) => {
|
|||||||
const querySearchPurchaser = (qs: string, cb: any) => fetchUserSuggestions(qs, cb)
|
const querySearchPurchaser = (qs: string, cb: any) => fetchUserSuggestions(qs, cb)
|
||||||
const handlePurchaserSelect = (item: any) => {
|
const handlePurchaserSelect = (item: any) => {
|
||||||
form.purchaser = item.value
|
form.purchaser = item.value
|
||||||
// 自动填充邮箱
|
|
||||||
if (item.email) {
|
if (item.email) {
|
||||||
form.purchaser_email = item.email
|
form.purchaser_email = item.email
|
||||||
}
|
}
|
||||||
@ -649,7 +666,22 @@ const fetchLinkSuggestions = async (query: string, cb: any, type: 'original' | '
|
|||||||
}
|
}
|
||||||
const querySearchLinks = (qs: string, cb: any, type: 'original' | 'detail') => fetchLinkSuggestions(qs, cb, type)
|
const querySearchLinks = (qs: string, cb: any, type: 'original' | 'detail') => fetchLinkSuggestions(qs, cb, type)
|
||||||
|
|
||||||
// 4. 币种
|
// 4. [新增] 库位建议 (基于 base_id)
|
||||||
|
const fetchLocationSuggestions = async (query: string, cb: any) => {
|
||||||
|
if (!form.base_id) { cb([]); return }
|
||||||
|
try {
|
||||||
|
const res: any = await getLocationSuggestions({ base_id: form.base_id })
|
||||||
|
if (res.code === 200) {
|
||||||
|
const locs = res.data.map((loc: string) => ({ value: loc }))
|
||||||
|
const filtered = query ? locs.filter((item:any) => item.value.toLowerCase().includes(query.toLowerCase())) : locs
|
||||||
|
cb(filtered)
|
||||||
|
} else { cb([]) }
|
||||||
|
} catch(e) { cb([]) }
|
||||||
|
}
|
||||||
|
const querySearchLocation = (qs: string, cb: any) => fetchLocationSuggestions(qs, cb)
|
||||||
|
|
||||||
|
|
||||||
|
// 5. 币种
|
||||||
const currencyOptions = [{value: 'CNY', desc: '人民币'}, {value: 'USD', desc: '美元'}, {value: 'EUR', desc: '欧元'}]
|
const currencyOptions = [{value: 'CNY', desc: '人民币'}, {value: 'USD', desc: '美元'}, {value: 'EUR', desc: '欧元'}]
|
||||||
const querySearchCurrency = (queryString: string, cb: any) => {
|
const querySearchCurrency = (queryString: string, cb: any) => {
|
||||||
const filtered = queryString ? currencyOptions.filter(item => item.value.toLowerCase().includes(queryString.toLowerCase()) || item.desc.toLowerCase().includes(queryString.toLowerCase())) : currencyOptions
|
const filtered = queryString ? currencyOptions.filter(item => item.value.toLowerCase().includes(queryString.toLowerCase()) || item.desc.toLowerCase().includes(queryString.toLowerCase())) : currencyOptions
|
||||||
@ -787,7 +819,7 @@ const handleUpdate = (row: any) => {
|
|||||||
source_link: row.source_link, detail_link: row.detail_link,
|
source_link: row.source_link, detail_link: row.detail_link,
|
||||||
arrival_photo: row.arrival_photo || [], inspection_report: row.inspection_report || []
|
arrival_photo: row.arrival_photo || [], inspection_report: row.inspection_report || []
|
||||||
})
|
})
|
||||||
// 回显图片,补全路径
|
// 回显图片
|
||||||
arrivalFileList.value = form.arrival_photo.map(url => ({ name: url.split('/').pop(), url: getImageUrl(url) }))
|
arrivalFileList.value = form.arrival_photo.map(url => ({ name: url.split('/').pop(), url: getImageUrl(url) }))
|
||||||
const reports = form.inspection_report || []
|
const reports = form.inspection_report || []
|
||||||
const reportImgs = reports.filter(r => !isExternalLink(r))
|
const reportImgs = reports.filter(r => !isExternalLink(r))
|
||||||
@ -834,18 +866,15 @@ const submitForm = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
// 图片/文件处理 (核心修复)
|
// 图片/文件处理
|
||||||
// ------------------------------------
|
// ------------------------------------
|
||||||
|
|
||||||
// 1. 路径补全
|
|
||||||
const getImageUrl = (url: string) => {
|
const getImageUrl = (url: string) => {
|
||||||
if (!url) return ''
|
if (!url) return ''
|
||||||
if (url.startsWith('http') || url.startsWith('https') || url.startsWith('blob:')) {
|
if (url.startsWith('http') || url.startsWith('https') || url.startsWith('blob:')) {
|
||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
// 获取 VITE_APP_BASE_API,如果未设置则默认为空
|
|
||||||
const apiBase = import.meta.env.VITE_APP_BASE_API || ''
|
const apiBase = import.meta.env.VITE_APP_BASE_API || ''
|
||||||
// 去除末尾斜杠
|
|
||||||
const baseUrl = apiBase.endsWith('/') ? apiBase.slice(0, -1) : apiBase
|
const baseUrl = apiBase.endsWith('/') ? apiBase.slice(0, -1) : apiBase
|
||||||
const path = url.startsWith('/') ? url : '/' + url
|
const path = url.startsWith('/') ? url : '/' + url
|
||||||
return baseUrl + path
|
return baseUrl + path
|
||||||
@ -861,7 +890,6 @@ const beforeAvatarUpload = (rawFile: any) => {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. 自定义上传 (修复回显)
|
|
||||||
const customUpload = async (options: any, targetField: 'arrival_photo' | 'inspection_report') => {
|
const customUpload = async (options: any, targetField: 'arrival_photo' | 'inspection_report') => {
|
||||||
const { file, onSuccess, onError } = options
|
const { file, onSuccess, onError } = options
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
@ -869,12 +897,9 @@ const customUpload = async (options: any, targetField: 'arrival_photo' | 'inspec
|
|||||||
try {
|
try {
|
||||||
const res: any = await uploadFile(formData)
|
const res: any = await uploadFile(formData)
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
const newUrl = res.data.url // 后端返回的相对路径
|
const newUrl = res.data.url
|
||||||
|
|
||||||
// 1. 存入表单数据 (相对路径)
|
|
||||||
form[targetField].push(newUrl)
|
form[targetField].push(newUrl)
|
||||||
|
|
||||||
// 2. 显式更新 fileList (完整路径,用于显示)
|
|
||||||
const fullUrl = getImageUrl(newUrl)
|
const fullUrl = getImageUrl(newUrl)
|
||||||
const fileObj = { name: file.name, url: fullUrl, status: 'success', uid: file.uid }
|
const fileObj = { name: file.name, url: fullUrl, status: 'success', uid: file.uid }
|
||||||
|
|
||||||
@ -887,7 +912,6 @@ const customUpload = async (options: any, targetField: 'arrival_photo' | 'inspec
|
|||||||
if (idx > -1) reportFileList.value[idx] = fileObj
|
if (idx > -1) reportFileList.value[idx] = fileObj
|
||||||
else reportFileList.value.push(fileObj)
|
else reportFileList.value.push(fileObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
ElMessage.success('上传成功')
|
ElMessage.success('上传成功')
|
||||||
onSuccess(res)
|
onSuccess(res)
|
||||||
} else {
|
} else {
|
||||||
@ -903,7 +927,6 @@ const customUpload = async (options: any, targetField: 'arrival_photo' | 'inspec
|
|||||||
const handleRemoveImage = async (uploadFile: any, targetField: 'arrival_photo' | 'inspection_report') => {
|
const handleRemoveImage = async (uploadFile: any, targetField: 'arrival_photo' | 'inspection_report') => {
|
||||||
try {
|
try {
|
||||||
const filename = uploadFile.url.split('/').pop()
|
const filename = uploadFile.url.split('/').pop()
|
||||||
// 尝试匹配完整路径或文件名
|
|
||||||
const urlToRemove = form[targetField].find(u => u.endsWith(filename)) || uploadFile.url
|
const urlToRemove = form[targetField].find(u => u.endsWith(filename)) || uploadFile.url
|
||||||
|
|
||||||
form[targetField] = form[targetField].filter(u => u !== urlToRemove)
|
form[targetField] = form[targetField].filter(u => u !== urlToRemove)
|
||||||
@ -938,18 +961,13 @@ const handleCameraConfirm = async (file: File) => {
|
|||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
const newUrl = res.data.url
|
const newUrl = res.data.url
|
||||||
const field = currentCameraField.value
|
const field = currentCameraField.value
|
||||||
|
|
||||||
// 更新表单
|
|
||||||
form[field].push(newUrl)
|
form[field].push(newUrl)
|
||||||
|
|
||||||
// 更新文件列表 (完整路径)
|
|
||||||
const fileObj = { name: file.name, url: getImageUrl(newUrl) }
|
const fileObj = { name: file.name, url: getImageUrl(newUrl) }
|
||||||
if (field === 'arrival_photo') {
|
if (field === 'arrival_photo') {
|
||||||
arrivalFileList.value.push(fileObj)
|
arrivalFileList.value.push(fileObj)
|
||||||
} else if (field === 'inspection_report') {
|
} else if (field === 'inspection_report') {
|
||||||
reportFileList.value.push(fileObj)
|
reportFileList.value.push(fileObj)
|
||||||
}
|
}
|
||||||
|
|
||||||
ElMessage.success('拍照上传成功')
|
ElMessage.success('拍照上传成功')
|
||||||
cameraDialogVisible.value = false
|
cameraDialogVisible.value = false
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user