192 lines
5.6 KiB
Vue
192 lines
5.6 KiB
Vue
<script>
|
|
import "~/assets/styles/UploadField.BbTCTv6C.css";
|
|
import { toDisplayString } from "vue";
|
|
import { mergeModels } from "vue";
|
|
import { useModel } from "vue";
|
|
import { ref } from "vue";
|
|
import { createCommentVNode } from "vue";
|
|
import { createElementBlock } from "vue";
|
|
import { Fragment } from "vue";
|
|
import { createElementVNode } from "vue";
|
|
import { createTextVNode } from "vue";
|
|
import { unref } from "vue";
|
|
import { defineComponent } from "vue";
|
|
import { openBlock } from "vue";
|
|
import { useApi } from "~/lib/auth.js";
|
|
import { t as _plugin_vue_export_helper_t } from "~/lib/_plugin-vue_export-helper.js";
|
|
var m = {
|
|
class: `field`,
|
|
},
|
|
h = {
|
|
key: 0,
|
|
},
|
|
g = {
|
|
class: `row`,
|
|
},
|
|
_ = [`accept`, `disabled`],
|
|
v = {
|
|
key: 0,
|
|
class: `state`,
|
|
},
|
|
y = {
|
|
class: `state ok`,
|
|
},
|
|
b = {
|
|
key: 2,
|
|
class: `state`,
|
|
},
|
|
x = {
|
|
key: 1,
|
|
class: `err`,
|
|
},
|
|
S = Object.assign(
|
|
_plugin_vue_export_helper_t(
|
|
defineComponent({
|
|
__name: `UploadField`,
|
|
props: mergeModels(
|
|
{
|
|
label: {},
|
|
hint: {},
|
|
accept: {},
|
|
},
|
|
{
|
|
modelValue: {
|
|
default: ``,
|
|
},
|
|
modelModifiers: {},
|
|
},
|
|
),
|
|
emits: mergeModels([`uploaded`], [`update:modelValue`]),
|
|
setup(t, { emit: u }) {
|
|
let p = useModel(t, `modelValue`),
|
|
S = u,
|
|
C = useApi(),
|
|
w = ref(!1),
|
|
T = ref(``),
|
|
E = ref(``);
|
|
async function D(e) {
|
|
let t = e.target,
|
|
n = t.files?.[0];
|
|
if (n) {
|
|
((w.value = !0), (T.value = ``));
|
|
try {
|
|
let e = await C.upload(n);
|
|
((p.value = e.save_name), (E.value = n.name), S(`uploaded`, e));
|
|
} catch (e) {
|
|
T.value = e instanceof Error ? e.message : `上传失败`;
|
|
} finally {
|
|
((w.value = !1), (t.value = ``));
|
|
}
|
|
}
|
|
}
|
|
function O() {
|
|
((p.value = ``), (E.value = ``));
|
|
}
|
|
return (n, r) => (
|
|
openBlock(),
|
|
createElementBlock(`div`, m, [
|
|
t.label
|
|
? (openBlock(),
|
|
createElementBlock(`label`, h, toDisplayString(t.label), 1))
|
|
: createCommentVNode(``, !0),
|
|
createElementVNode(`div`, g, [
|
|
createElementVNode(
|
|
`input`,
|
|
{
|
|
type: `file`,
|
|
accept: t.accept,
|
|
disabled: unref(w),
|
|
onChange: D,
|
|
},
|
|
null,
|
|
40,
|
|
_,
|
|
),
|
|
unref(w)
|
|
? (openBlock(),
|
|
createElementBlock(`span`, v, [
|
|
...(r[0] ||= [
|
|
createElementVNode(
|
|
`i`,
|
|
{
|
|
class: `pi pi-spin pi-spinner`,
|
|
},
|
|
null,
|
|
-1,
|
|
),
|
|
createTextVNode(` 上传中…`, -1),
|
|
]),
|
|
]))
|
|
: p.value
|
|
? (openBlock(),
|
|
createElementBlock(
|
|
Fragment,
|
|
{
|
|
key: 1,
|
|
},
|
|
[
|
|
createElementVNode(`span`, y, [
|
|
(r[1] ||= createElementVNode(
|
|
`i`,
|
|
{
|
|
class: `pi pi-check-circle`,
|
|
},
|
|
null,
|
|
-1,
|
|
)),
|
|
createTextVNode(
|
|
` ` + toDisplayString(unref(E) || `已上传`),
|
|
1,
|
|
),
|
|
]),
|
|
createElementVNode(
|
|
`button`,
|
|
{
|
|
type: `button`,
|
|
class: `rm`,
|
|
onClick: O,
|
|
},
|
|
[
|
|
...(r[2] ||= [
|
|
createElementVNode(
|
|
`i`,
|
|
{
|
|
class: `pi pi-times`,
|
|
},
|
|
null,
|
|
-1,
|
|
),
|
|
]),
|
|
],
|
|
),
|
|
],
|
|
64,
|
|
))
|
|
: t.hint
|
|
? (openBlock(),
|
|
createElementBlock(
|
|
`span`,
|
|
b,
|
|
toDisplayString(t.hint),
|
|
1,
|
|
))
|
|
: createCommentVNode(``, !0),
|
|
]),
|
|
unref(T)
|
|
? (openBlock(),
|
|
createElementBlock(`span`, x, toDisplayString(unref(T)), 1))
|
|
: createCommentVNode(``, !0),
|
|
])
|
|
);
|
|
},
|
|
}),
|
|
[[`__scopeId`, `data-v-8267b59f`]],
|
|
),
|
|
{
|
|
__name: `UploadField`,
|
|
},
|
|
);
|
|
export {};
|
|
export default S;
|
|
</script>
|