up
This commit is contained in:
@@ -400,10 +400,13 @@ func ApiWorkOrder(r *gin.RouterGroup) {
|
||||
}
|
||||
|
||||
canModify := canModifyWorkOrder(user.ID, order.UserID)
|
||||
// 所有登录用户都可以提交进度
|
||||
canCommit := true
|
||||
|
||||
ReturnJson(ctx, "apiOK", gin.H{
|
||||
"order": order,
|
||||
"canModify": canModify,
|
||||
"canCommit": canCommit,
|
||||
"photos": files,
|
||||
"commits": commitsWithPhotos,
|
||||
})
|
||||
@@ -457,11 +460,6 @@ func ApiWorkOrder(r *gin.RouterGroup) {
|
||||
return
|
||||
}
|
||||
|
||||
if !canModifyWorkOrder(user.ID, order.UserID) {
|
||||
ReturnJson(ctx, "no_permission", nil)
|
||||
return
|
||||
}
|
||||
|
||||
oldStatus := order.CurrentStatus
|
||||
models.DB.Model(&order).Update("current_status", from.Status)
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import { ref } from 'vue'
|
||||
import { usersApi } from '@/api/users';
|
||||
|
||||
const usersInfo = ref([]);
|
||||
// 正在请求中的 promiseMap,同一 userID 只发一次请求
|
||||
const inflightRequests = new Map();
|
||||
|
||||
export const useUsersStore = defineStore('users', () => {
|
||||
|
||||
@@ -13,16 +15,33 @@ export const useUsersStore = defineStore('users', () => {
|
||||
}
|
||||
|
||||
function fetchUser(userID) {
|
||||
// 缓存命中则不再请求(依赖 usersInfo 的响应式)
|
||||
// 已缓存则直接返回
|
||||
if (getUserFromUserID(userID)) return
|
||||
usersApi.getUserInfoFromUserID(userID).then((r) => {
|
||||
|
||||
// 同一请求已在飞中,等待它完成后再更新缓存引用
|
||||
if (inflightRequests.has(userID)) return
|
||||
|
||||
// 立即占位:同步标记为"请求中",同一帧内后续调用能命中
|
||||
const placeholder = { UserID: userID, _loading: true }
|
||||
usersInfo.value.push(placeholder)
|
||||
|
||||
const promise = usersApi.getUserInfoFromUserID(userID).then((r) => {
|
||||
if (r.errCode == 0 && r.raw.err_code == 0 && r.raw.return?.userinfo) {
|
||||
// 防止并发写入重复数据
|
||||
if (!usersInfo.value.find(item => item.UserID === userID)) {
|
||||
usersInfo.value.push(r.raw.return.userinfo)
|
||||
const info = r.raw.return.userinfo
|
||||
// 替换占位对象为真实数据
|
||||
const idx = usersInfo.value.findIndex(item => item.UserID === userID)
|
||||
if (idx !== -1) {
|
||||
usersInfo.value.splice(idx, 1, info)
|
||||
}
|
||||
} else {
|
||||
// 请求失败,移除占位
|
||||
usersInfo.value = usersInfo.value.filter(item => item.UserID !== userID)
|
||||
}
|
||||
}).finally(() => {
|
||||
inflightRequests.delete(userID)
|
||||
})
|
||||
|
||||
inflightRequests.set(userID, promise)
|
||||
}
|
||||
|
||||
function getUsernameFromUserID(userID) {
|
||||
|
||||
@@ -33,6 +33,7 @@ const order = ref(null)
|
||||
const photos = ref([])
|
||||
const commits = ref([])
|
||||
const canModify = ref(false)
|
||||
const canCommit = ref(false)
|
||||
const loading = ref(true)
|
||||
const notFound = ref(false)
|
||||
|
||||
@@ -117,6 +118,7 @@ async function fetchOrder() {
|
||||
if (errCode === 0 && data) {
|
||||
order.value = data.order ?? null
|
||||
canModify.value = data.canModify ?? false
|
||||
canCommit.value = data.canCommit ?? false
|
||||
photos.value = data.photos ?? []
|
||||
commits.value = data.commits ?? []
|
||||
// 初始化进度提交状态为当前状态
|
||||
@@ -376,9 +378,9 @@ onUnmounted(() => {
|
||||
<span class="text-sm text-gray-400">{{ formatDate(order?.CreatedAt) }}</span>
|
||||
</div>
|
||||
|
||||
<!-- 状态快捷切换(有权限才显示) -->
|
||||
<!-- 状态快捷切换(所有登录用户可见) -->
|
||||
<div
|
||||
v-if="canModify"
|
||||
v-if="canCommit"
|
||||
class="flex flex-wrap items-center gap-2 border-b border-gray-100 px-6 py-3 dark:border-dk-muted"
|
||||
>
|
||||
<span class="text-sm text-gray-500 dark:text-gray-400">{{ t('purchase.change_status') }}:</span>
|
||||
@@ -439,8 +441,8 @@ onUnmounted(() => {
|
||||
<h3 class="text-base font-semibold text-gray-900 dark:text-white">{{ t('work_order.commit_history') }}</h3>
|
||||
</div>
|
||||
|
||||
<!-- 新增进度表单(有权限才显示) -->
|
||||
<div v-if="canModify" class="border-t border-gray-100 px-6 py-5 dark:border-dk-muted">
|
||||
<!-- 新增进度表单(所有登录用户可见) -->
|
||||
<div v-if="canCommit" class="border-t border-gray-100 px-6 py-5 dark:border-dk-muted">
|
||||
<h4 class="mb-3 text-sm font-semibold text-gray-700 dark:text-gray-300">{{ t('work_order.add_commit') }}</h4>
|
||||
|
||||
<!-- 第一行:进度状态、关联采购订单 -->
|
||||
|
||||
Reference in New Issue
Block a user