Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
黄南光
/
auto-restock
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 94ab5d0d
authored
Dec 04, 2026
by
黄南光
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
修改图片样式
1 parent
b3a3660d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
139 additions
and
6 deletions
server/tests/test_im_order.py
web/src/mobile/OrderPage.vue
web/src/mobile/mobile.css
server/tests/test_im_order.py
0 → 100644
View file @
94ab5d0
"""按顺序发多张图(建单截图):每张等回显(真正发到会话里)再发下一张,全部发完才发文字。
网关发送接口只返回「已受理」,图片比文字慢,不等回显的话文字会跑到最后一张图前面。"""
from
__future__
import
annotations
import
asyncio
import
datetime
as
dt
import
time
from
pathlib
import
Path
import
pytest
from
app.services
import
im
,
imhub
ITEMS
=
[(
Path
(
"po_list.png"
),
""
),
(
Path
(
"po_detail.png"
),
""
),
(
Path
(
"po_detail_2.png"
),
""
)]
class
FakeGw
:
"""假网关:发出去的图片要再被拉 lag 次消息之后才出现在聊天记录里(模拟图片落地慢)。"""
def
__init__
(
self
,
lag
:
int
=
2
,
echo
:
bool
=
True
,
url_same
:
bool
=
True
)
->
None
:
self
.
lag
,
self
.
echo
,
self
.
url_same
=
lag
,
echo
,
url_same
self
.
polls
=
0
self
.
msgs
:
list
[
tuple
[
int
,
dict
]]
=
[]
# (第几次拉取起可见, 消息)
self
.
log
:
list
[
str
]
=
[]
# 发送顺序:img:<文件名> / text:<内容>
self
.
bad
:
list
[
str
]
=
[]
# 发送时上一张图还没落地的记录
def
visible
(
self
,
contact
:
str
|
None
=
None
)
->
list
[
dict
]:
return
[
m
for
at
,
m
in
self
.
msgs
if
at
<=
self
.
polls
and
(
contact
is
None
or
m
.
get
(
"to"
)
in
(
None
,
contact
))]
def
_check_prev_landed
(
self
,
what
:
str
)
->
None
:
sent_imgs
=
sum
(
1
for
x
in
self
.
log
if
x
.
startswith
(
"img:"
))
landed
=
[
m
for
m
in
self
.
visible
()
if
m
[
"msg_id"
]
.
startswith
(
"e"
)]
if
self
.
echo
and
len
(
landed
)
<
sent_imgs
:
self
.
bad
.
append
(
what
)
def
send_image
(
self
,
bot
,
to
,
path
,
url
=
""
,
pic
=
""
):
self
.
_check_prev_landed
(
f
"img:{Path(path).name}"
)
self
.
log
.
append
(
f
"img:{Path(path).name}"
)
if
self
.
echo
:
n
=
len
(
self
.
msgs
)
self
.
msgs
.
append
((
self
.
polls
+
self
.
lag
,
{
"msg_id"
:
f
"e{n}"
,
"to"
:
str
(
to
),
"sender_type"
:
"1"
,
"msg_type"
:
"image"
,
"url"
:
pic
if
self
.
url_same
else
f
"https://gw.example.com/other/{n}.jpg"
,
"msg_time"
:
dt
.
datetime
.
now
()
.
astimezone
()
.
isoformat
()}))
return
True
,
""
,
pic
or
"x"
def
send_text
(
self
,
bot
,
to
,
text
,
at
=
None
):
self
.
_check_prev_landed
(
f
"text:{text}"
)
self
.
log
.
append
(
f
"text:{text}"
)
return
True
,
""
def
fetch_msgs
(
self
,
bot
,
contact
,
start
,
end
):
self
.
polls
+=
1
return
self
.
visible
(
str
(
contact
))
@pytest.fixture
()
def
gw
(
monkeypatch
,
kit
,
outbox
):
g
=
FakeGw
()
monkeypatch
.
setattr
(
imhub
,
"send_image"
,
g
.
send_image
)
monkeypatch
.
setattr
(
imhub
,
"send_text"
,
g
.
send_text
)
monkeypatch
.
setattr
(
imhub
,
"fetch_msgs"
,
g
.
fetch_msgs
)
monkeypatch
.
setattr
(
im
,
"IMAGE_ECHO_WAIT"
,
5.0
)
monkeypatch
.
setattr
(
im
,
"IMAGE_ECHO_POLL"
,
0.01
)
im
.
SYNC
.
clear
()
yield
g
im
.
SYNC
.
clear
()
def
send_all
(
t
,
items
=
ITEMS
,
targets
=
None
)
->
int
:
n
=
asyncio
.
run
(
im
.
send_images
(
targets
or
[
t
],
items
,
ref
=
"restock:1"
))
im
.
send_to
(
t
,
"✅ 单建好了"
)
return
n
def
test_images_land_in_order_before_text
(
gw
,
kit
):
t
=
kit
.
target
()
assert
send_all
(
t
)
==
3
assert
gw
.
log
==
[
"img:po_list.png"
,
"img:po_detail.png"
,
"img:po_detail_2.png"
,
"text:✅ 单建好了"
]
assert
gw
.
bad
==
[]
# 每条都是在上一张图落地之后才发的
def
test_echo_url_differs_still_advances_by_order
(
gw
,
kit
):
gw
.
url_same
=
False
# 发之前会话里已经有一张机器人图片:不能被当成这批第一张的回显
gw
.
msgs
.
append
((
0
,
{
"msg_id"
:
"old"
,
"sender_type"
:
"1"
,
"msg_type"
:
"image"
,
"url"
:
"https://gw/old.jpg"
,
"msg_time"
:
dt
.
datetime
.
now
()
.
astimezone
()
.
isoformat
()}))
t
=
kit
.
target
()
assert
send_all
(
t
)
==
3
assert
gw
.
log
[
-
1
]
==
"text:✅ 单建好了"
assert
gw
.
bad
==
[]
# 预先就有的那张不算回显,仍是上一张落地才发下一条
def
test_no_echo_waits_at_most_cap_then_sends_text
(
gw
,
kit
,
monkeypatch
):
gw
.
echo
=
False
monkeypatch
.
setattr
(
im
,
"IMAGE_ECHO_WAIT"
,
0.2
)
t
=
kit
.
target
()
t0
=
time
.
time
()
assert
send_all
(
t
)
==
3
assert
gw
.
log
[
-
1
]
==
"text:✅ 单建好了"
assert
time
.
time
()
-
t0
<
3
*
0.2
+
2
# 每张最多等 IMAGE_ECHO_WAIT
def
test_sync_down_skips_echo_wait
(
gw
,
kit
,
monkeypatch
):
t
=
kit
.
target
()
im
.
SYNC
[
t
[
"id"
]]
=
{
"down_since"
:
time
.
time
()
-
60
}
monkeypatch
.
setattr
(
im
,
"IMAGE_TAIL_GAP"
,
0.01
)
assert
send_all
(
t
)
==
3
assert
gw
.
polls
==
0
# 同步中断:不去拉回显
assert
gw
.
log
[
-
1
]
==
"text:✅ 单建好了"
def
test_preupload_once_shared_by_targets
(
gw
,
kit
,
monkeypatch
):
uploads
:
list
[
str
]
=
[]
monkeypatch
.
setattr
(
imhub
,
"upload"
,
lambda
p
:
(
uploads
.
append
(
Path
(
p
)
.
name
),
(
f
"https://oss.test/{Path(p).name}"
,
""
))[
1
])
t
=
kit
.
target
()
t2
=
dict
(
t
,
id
=
t
[
"id"
]
+
100000
,
contact_id
=
"group-other"
,
name
=
"另一个群"
)
assert
asyncio
.
run
(
im
.
send_images
([
t
,
t2
],
ITEMS
))
==
3
assert
sorted
(
uploads
)
==
sorted
(
p
.
name
for
p
,
_
in
ITEMS
)
# 每张只传一次,两个群共用
assert
sum
(
1
for
x
in
gw
.
log
if
x
.
startswith
(
"img:"
))
==
6
web/src/mobile/OrderPage.vue
View file @
94ab5d0
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
<
script
setup
lang=
"ts"
>
<
script
setup
lang=
"ts"
>
import
'vant/lib/index.css'
import
'vant/lib/index.css'
import
{
Button
as
VanButton
,
Checkbox
as
VanCheckbox
,
Empty
as
VanEmpty
,
import
{
Button
as
VanButton
,
Checkbox
as
VanCheckbox
,
Empty
as
VanEmpty
,
Loading
as
VanLoading
,
showConfirmDialog
,
showFailToast
,
showSuccessToast
,
Loading
as
VanLoading
,
showConfirmDialog
,
showFailToast
,
show
ImagePreview
,
show
SuccessToast
,
Stepper
as
VanStepper
}
from
'vant'
Stepper
as
VanStepper
}
from
'vant'
import
{
computed
,
onMounted
,
onUnmounted
,
ref
}
from
'vue'
import
{
computed
,
onMounted
,
onUnmounted
,
ref
}
from
'vue'
import
{
useRoute
}
from
'vue-router'
import
{
useRoute
}
from
'vue-router'
...
@@ -361,6 +361,16 @@ async function cancel() {
...
@@ -361,6 +361,16 @@ async function cancel() {
const tone = computed(() => STAGE[status.value]?.tone || 'info')
const tone = computed(() => STAGE[status.value]?.tone || 'info')
function sheetClicked() { event('sheet_download', { order_no: st.value?.run.order_no }) }
function sheetClicked() { event('sheet_download', { order_no: st.value?.run.order_no }) }
const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').slice(11, 19))
const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').slice(11, 19))
/** 采购单截图预览按设备分流:
* - 触屏手机 / 平板:Vant 全屏预览(黑底、双指 / 双击缩放、左右滑、点一下关闭、返回键关闭),像点普通图片一样,没有工具栏按钮;
* - 电脑(企微桌面端 / 浏览器,有鼠标):el-image 自带查看器,大图不变形。
* 按指针类型判断而不是按宽度,电脑窗口拉窄也还是电脑的预览。 */
const touch = typeof window !== 'undefined' && window.matchMedia('(hover: none) and (pointer: coarse)').matches
const shotUrls = computed<string[]>(() => (st.value?.shots || []).map((x: any) => x.url))
function openShot(i: number) {
if (!touch) return
showImagePreview({ images: shotUrls.value, startPosition: i, showIndex: shotUrls.value.length > 1, closeable: false, loop: false })
}
</
script
>
</
script
>
<
template
>
<
template
>
...
@@ -473,10 +483,11 @@ const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').sli
...
@@ -473,10 +483,11 @@ const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').sli
</div>
</div>
<div
v-else-if=
"status === 'awaiting_submit'"
class=
"m-po-sub"
>
不过期 · 提交前会先到 DMS 查这张单的状态
</div>
<div
v-else-if=
"status === 'awaiting_submit'"
class=
"m-po-sub"
>
不过期 · 提交前会先到 DMS 查这张单的状态
</div>
<div
v-if=
"st.shots_fallback"
class=
"m-fallback"
>
⚠ DMS 页面截图失败,以下截图是用 DMS 接口实际返回的数据渲染的,不是 DMS 原页面
</div>
<div
v-if=
"st.shots_fallback"
class=
"m-fallback"
>
⚠ DMS 页面截图失败,以下截图是用 DMS 接口实际返回的数据渲染的,不是 DMS 原页面
</div>
<!-- 预览挂到 body:不受缩略图样式影响,点开大图不变形 -->
<!-- 缩略图统一用 el-image(固定高、宽按比例)。点开:手机走 Vant 全屏预览(openShot),电脑走 el-image 查看器;
两种预览都挂到 body,不受缩略图样式影响,大图不变形 -->
<div
v-if=
"st.shots.length"
class=
"m-shots"
>
<div
v-if=
"st.shots.length"
class=
"m-shots"
>
<el-image
v-for=
"
s in st.shots"
:key=
"s.id"
:src=
"s.url"
:preview-src-list=
"st.shots.map((x: any) => x.url)
"
<el-image
v-for=
"
(s, i) in st.shots"
:key=
"s.id"
:src=
"s.url"
:preview-src-list=
"touch ? [] : shotUrls
"
:initial-index=
"
st.shots.findIndex((x: any) => x.id === s.id)"
fit=
"contain"
preview-teleported
alt=
"采购单截图
"
/>
:initial-index=
"
i"
fit=
"contain"
preview-teleported
alt=
"采购单截图"
@
click=
"openShot(i)
"
/>
</div>
</div>
<!-- 采购明细清单:卡片底部的蓝色小按钮;已提交才能导出,待提交时置灰 -->
<!-- 采购明细清单:卡片底部的蓝色小按钮;已提交才能导出,待提交时置灰 -->
<div
v-if=
"st.sheet || (st.run.order_no && !submitted)"
class=
"m-sheet-row"
>
<div
v-if=
"st.sheet || (st.run.order_no && !submitted)"
class=
"m-sheet-row"
>
...
@@ -578,7 +589,7 @@ const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').sli
...
@@ -578,7 +589,7 @@ const fetchedAt = computed(() => String(st.value?.run.data_fetched_at || '').sli
<a
v-if=
"editing && edits[l.part_no]?.modified"
class=
"m-reset"
@
click=
"reset(l)"
>
恢复默认 {{ l.default_expected }}
</a>
<a
v-if=
"editing && edits[l.part_no]?.modified"
class=
"m-reset"
@
click=
"reset(l)"
>
恢复默认 {{ l.default_expected }}
</a>
</div>
</div>
<div
class=
"m-cells"
>
<div
class=
"m-cells"
>
<div><span>
出库
</span><b
class=
"hi"
>
{{ fmtNum(l.outbound_qty) }}
</b></div>
<div><span>
出库
</span><b>
{{ fmtNum(l.outbound_qty) }}
</b></div>
<div><span>
库存
</span><b>
{{ fmtNum(l.stock) }}
</b></div>
<div><span>
库存
</span><b>
{{ fmtNum(l.stock) }}
</b></div>
<div><span>
在途
</span><b>
{{ fmtNum(l.in_transit) }}
</b></div>
<div><span>
在途
</span><b>
{{ fmtNum(l.in_transit) }}
</b></div>
<div><span>
月均
</span><b>
{{ fmtNum(l.mad) }}
</b></div>
<div><span>
月均
</span><b>
{{ fmtNum(l.mad) }}
</b></div>
...
...
web/src/mobile/mobile.css
View file @
94ab5d0
...
@@ -18,6 +18,9 @@
...
@@ -18,6 +18,9 @@
min-height
:
100vh
;
background
:
var
(
--c-bg
);
color
:
var
(
--c-text
);
padding-bottom
:
128px
;
}
min-height
:
100vh
;
background
:
var
(
--c-bg
);
color
:
var
(
--c-text
);
padding-bottom
:
128px
;
}
/* 确认弹窗挂在 body 上、不在 .m 里,单独把确认按钮接成丰田红(后台用 Element Plus,不受影响) */
/* 确认弹窗挂在 body 上、不在 .m 里,单独把确认按钮接成丰田红(后台用 Element Plus,不受影响) */
.van-dialog
{
--van-dialog-confirm-button-text-color
:
#e60012
;
}
.van-dialog
{
--van-dialog-confirm-button-text-color
:
#e60012
;
}
/* 手机上点截图的全屏预览(Vant showImagePreview,同样挂在 body):纯黑底,和手机自带看图一样,不透出后面的页面 */
.van-image-preview
{
--van-image-preview-overlay-background
:
#000
;
}
.van-image-preview__overlay
{
background
:
#000
;
}
.m-loading
{
min-height
:
60vh
;
display
:
grid
;
place-items
:
center
;
}
.m-loading
{
min-height
:
60vh
;
display
:
grid
;
place-items
:
center
;
}
/* 页头:--hp 是状态色(底部光条、状态标签、第一格数字),默认 / 提醒用红,完成用绿,出错用亮红,其他用灰 */
/* 页头:--hp 是状态色(底部光条、状态标签、第一格数字),默认 / 提醒用红,完成用绿,出错用亮红,其他用灰 */
.m-hero
{
--hp
:
#e60012
;
padding
:
20px
18px
18px
;
color
:
#fff
;
.m-hero
{
--hp
:
#e60012
;
padding
:
20px
18px
18px
;
color
:
#fff
;
...
@@ -97,7 +100,6 @@
...
@@ -97,7 +100,6 @@
.m-cells
>
div
+
div
{
border-left
:
1px
solid
var
(
--c-border
);
}
.m-cells
>
div
+
div
{
border-left
:
1px
solid
var
(
--c-border
);
}
.m-cells
span
{
display
:
block
;
color
:
var
(
--c-text-3
);
font-size
:
10.5px
;
white-space
:
nowrap
;
}
.m-cells
span
{
display
:
block
;
color
:
var
(
--c-text-3
);
font-size
:
10.5px
;
white-space
:
nowrap
;
}
.m-cells
b
{
display
:
block
;
color
:
var
(
--c-text
);
font-size
:
13px
;
font-variant-numeric
:
tabular-nums
;
}
.m-cells
b
{
display
:
block
;
color
:
var
(
--c-text
);
font-size
:
13px
;
font-variant-numeric
:
tabular-nums
;
}
.m-cells
b
.hi
{
color
:
var
(
--c-primary
);
}
.m-card
{
margin
:
0
12px
10px
;
background
:
var
(
--c-surface
);
border-radius
:
12px
;
padding
:
12px
14px
;
box-shadow
:
var
(
--shadow
);
border
:
1px
solid
var
(
--c-border
);
}
.m-card
{
margin
:
0
12px
10px
;
background
:
var
(
--c-surface
);
border-radius
:
12px
;
padding
:
12px
14px
;
box-shadow
:
var
(
--shadow
);
border
:
1px
solid
var
(
--c-border
);
}
.m-po
{
margin-top
:
12px
;
}
.m-po
{
margin-top
:
12px
;
}
.m-po.ok
{
border-color
:
color-mix
(
in
srgb
,
var
(
--c-ok
)
30%
,
var
(
--c-surface
));
background
:
color-mix
(
in
srgb
,
var
(
--c-ok-soft
)
55%
,
var
(
--c-surface
));
}
.m-po.ok
{
border-color
:
color-mix
(
in
srgb
,
var
(
--c-ok
)
30%
,
var
(
--c-surface
));
background
:
color-mix
(
in
srgb
,
var
(
--c-ok-soft
)
55%
,
var
(
--c-surface
));
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment