This commit is contained in:
2025-09-27 22:57:59 +08:00
parent 8a458ff0a4
commit ed26244cdb
12585 changed files with 1914308 additions and 3474 deletions

View File

@@ -1,6 +1,8 @@
"use strict";
const common_vendor = require("../common/vendor.js");
const common_http = require("../common/http.js");
const common_config = require("../common/config.js");
const common_assets = require("../common/assets.js");
const ITEM_SIZE = 210;
const GAP = 18;
const COLS = 3;
@@ -25,6 +27,14 @@ const _sfc_main = {
areaHeight() {
const rows = Math.ceil((this.innerList.length + 1) / COLS) || 1;
return rows * ITEM_SIZE + (rows - 1) * GAP;
},
adderStyle() {
const index = this.innerList.length;
const row = Math.floor(index / COLS);
const col = index % COLS;
const x = px(col * (ITEM_SIZE + GAP));
const y = px(row * (ITEM_SIZE + GAP));
return { left: x + "rpx", top: y + "rpx" };
}
},
watch: {
@@ -33,7 +43,7 @@ const _sfc_main = {
handler(list) {
const mapped = (list || []).map((u, i) => ({
uid: String(i) + "_" + (u.id || u.url || Math.random().toString(36).slice(2)),
url: typeof u === "string" ? u : u.url || "",
url: this.ensureAbsoluteUrl(typeof u === "string" ? u : u.url || ""),
x: this.posOf(i).x,
y: this.posOf(i).y
}));
@@ -42,6 +52,14 @@ const _sfc_main = {
}
},
methods: {
ensureAbsoluteUrl(u) {
if (!u)
return "";
const s = String(u);
if (s.startsWith("http://") || s.startsWith("https://"))
return s;
return common_config.API_BASE_URL + (s.startsWith("/") ? s : "/" + s);
},
posOf(index) {
const row = Math.floor(index / COLS);
const col = index % COLS;
@@ -75,7 +93,7 @@ const _sfc_main = {
var _a;
try {
const resp = await common_http.upload(this.uploadPath, filePath, this.formData, this.uploadFieldName);
const url = (resp == null ? void 0 : resp.url) || ((_a = resp == null ? void 0 : resp.data) == null ? void 0 : _a.url) || (resp == null ? void 0 : resp.path) || "";
const url = this.ensureAbsoluteUrl((resp == null ? void 0 : resp.url) || ((_a = resp == null ? void 0 : resp.data) == null ? void 0 : _a.url) || (resp == null ? void 0 : resp.path) || "");
if (!url)
throw new Error("上传响应无 url");
this.innerList.push({ uid: Math.random().toString(36).slice(2), url, ...this.posOf(this.innerList.length) });
@@ -131,12 +149,14 @@ function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
i: common_vendor.o(($event) => $options.onMoveEnd(index), img.uid)
};
}),
b: $data.innerList.length < $props.max
b: common_assets._imports_0$4,
c: $data.innerList.length < $props.max
}, $data.innerList.length < $props.max ? {
c: common_vendor.o((...args) => $options.choose && $options.choose(...args))
d: common_vendor.s($options.adderStyle),
e: common_vendor.o((...args) => $options.choose && $options.choose(...args))
} : {}, {
d: $options.areaHeight + "rpx",
e: $options.areaHeight + "rpx"
f: $options.areaHeight + "rpx",
g: $options.areaHeight + "rpx"
});
}
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);

View File

@@ -1 +1 @@
<view class="uploader"><view class="grid" style="{{'height:' + e}}"><movable-area class="area" style="{{'height:' + d}}"><movable-view wx:for="{{a}}" wx:for-item="img" wx:key="d" class="cell" style="{{img.e}}" direction="{{'all'}}" damping="{{40}}" friction="{{2}}" x="{{img.f}}" y="{{img.g}}" bindchange="{{img.h}}" bindtouchend="{{img.i}}"><image src="{{img.a}}" mode="aspectFill" class="thumb" bindtap="{{img.b}}"/><view class="remove" catchtap="{{img.c}}">×</view></movable-view><view wx:if="{{b}}" class="adder" bindtap="{{c}}"><text></text></view></movable-area></view></view>
<view class="uploader"><view class="grid" style="{{'height:' + g}}"><movable-area class="area" style="{{'height:' + f}}"><movable-view wx:for="{{a}}" wx:for-item="img" wx:key="d" class="cell" style="{{img.e}}" direction="{{'all'}}" damping="{{40}}" friction="{{2}}" x="{{img.f}}" y="{{img.g}}" bindchange="{{img.h}}" bindtouchend="{{img.i}}"><image src="{{img.a}}" mode="aspectFill" class="thumb" bindtap="{{img.b}}"/><image class="remove" src="{{b}}" mode="aspectFit" catchtap="{{img.c}}"/></movable-view><view wx:if="{{c}}" class="adder" style="{{d}}" bindtap="{{e}}"><text></text></view></movable-area></view></view>

View File

@@ -9,7 +9,7 @@
}
.thumb { width: 100%; height: 100%;
}
.remove { position: absolute; right: 6rpx; top: 6rpx; background: rgba(0,0,0,0.45); color: #fff; width: 40rpx; height: 40rpx; text-align: center; line-height: 40rpx; border-radius: 20rpx; font-size: 28rpx;
.remove { position: absolute; right: 6rpx; top: 6rpx; width: 42rpx; height: 42rpx;
}
.adder { width: 210rpx; height: 210rpx; border: 2rpx dashed #ccc; border-radius: 12rpx; display: flex; align-items: center; justify-content: center; color: #999; position: absolute; left: 0; top: 0;
}