限制人脸图片上传大小

This commit is contained in:
ctw committed 2025-01-19 13:57:09 +08:00
1 parent e5b7861132
commit 57e956348e
4 files changed
+393 -377

No files matched your search

+3 -1
View File
@@ -18,4 +18,6 @@ dist
*.ntvs*
*.njsproj
*.sln
*.sw?
*.sw?
.env
+295 -295
View File
@@ -1,296 +1,296 @@
{
"easycom": {
"autoscan": true,
"custom": {
"^base-(.*)": "@/sheep/components/base/base-$1/base-$1.vue",
"^crud-(.*)": "@/sheep/components/crud/crud-$1/crud-$1.vue",
"^tm-(.*)": "@/uni_modules/tm-ui/components/tm-$1/tm-$1.vue",
"^(?!z-paging-refresh|z-paging-load-more)z-paging(.*)": "z-paging/components/z-paging$1/z-paging$1.vue"
}
},
"pages": [
{
"path": "pages/tabbar/home",
"style": {
"navigationBarTitleText": "首页",
"disableScroll": true
}
},
{
"path": "pages/tabbar/shop",
"style": {
"navigationBarTitleText": "商店",
"disableScroll": true
}
},
{
"path": "pages/tabbar/order",
"style": {
"navigationBarTitleText": "订单",
"disableScroll": true
}
},
{
"path": "pages/tabbar/my",
"style": {
"navigationBarTitleText": "我的",
"disableScroll": true
}
}
],
"subPackages": [
{
"root": "pages/order",
"pages": []
},
{
"root": "pages/shop",
"pages": [
{
"path": "detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "product-detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/apply",
"pages": [
{
"path": "foreign-apply",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "foreign-list",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "foreign-items",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "stride-apply",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "stride-list",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "stride-items",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/boxes",
"pages": [
{
"path": "apply",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "list",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "apply-list",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/merchant",
"pages": [
{
"path": "detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "food",
"style": {
"navigationBarTitleText": "菜谱",
"navigationBarBackgroundColor": "#1777FF",
"disableScroll": true
}
},
{
"path": "product-detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/order",
"pages": [
{
"path": "detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/refund",
"pages": [
{
"path": "apply",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "history",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/test",
"pages": [
{
"path": "login",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/wallet",
"pages": [
{
"path": "list",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "recharge",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/human-face",
"pages": [
{
"path": "list",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "apply",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "浦江小程序",
"navigationBarBackgroundColor": "#1777FF",
"backgroundColor": "#ecf4f9",
"navigationStyle": "custom"
},
"tabBar": {
"list": [
{
"pagePath": "pages/tabbar/home",
"text": "首页",
"iconPath": "static/tabbar/home.png",
"selectedIconPath": "static/tabbar/home-select.png"
},
{
"pagePath": "pages/tabbar/shop",
"text": "超市",
"iconPath": "static/tabbar/shop.png",
"selectedIconPath": "static/tabbar/shop-select.png"
},
{
"pagePath": "pages/tabbar/order",
"text": "订单",
"iconPath": "static/tabbar/order.png",
"selectedIconPath": "static/tabbar/order-select.png"
},
{
"pagePath": "pages/tabbar/my",
"text": "我的",
"iconPath": "static/tabbar/my.png",
"selectedIconPath": "static/tabbar/my-select.png"
}
]
}
}
"easycom": {
"autoscan": true,
"custom": {
"^base-(.*)": "@/sheep/components/base/base-$1/base-$1.vue",
"^crud-(.*)": "@/sheep/components/crud/crud-$1/crud-$1.vue",
"^tm-(.*)": "@/uni_modules/tm-ui/components/tm-$1/tm-$1.vue",
"^(?!z-paging-refresh|z-paging-load-more)z-paging(.*)": "z-paging/components/z-paging$1/z-paging$1.vue"
}
},
"pages": [
{
"path": "pages/tabbar/home",
"style": {
"navigationBarTitleText": "首页",
"disableScroll": true
}
},
{
"path": "pages/tabbar/shop",
"style": {
"navigationBarTitleText": "商店",
"disableScroll": true
}
},
{
"path": "pages/tabbar/order",
"style": {
"navigationBarTitleText": "订单",
"disableScroll": true
}
},
{
"path": "pages/tabbar/my",
"style": {
"navigationBarTitleText": "我的",
"disableScroll": true
}
}
],
"subPackages": [
{
"root": "pages/order",
"pages": []
},
{
"root": "pages/shop",
"pages": [
{
"path": "detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "product-detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/apply",
"pages": [
{
"path": "foreign-apply",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "foreign-list",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "foreign-items",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "stride-apply",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "stride-list",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "stride-items",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/boxes",
"pages": [
{
"path": "apply",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "list",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "apply-list",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/merchant",
"pages": [
{
"path": "detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "food",
"style": {
"navigationBarTitleText": "菜谱",
"navigationBarBackgroundColor": "#1777FF",
"disableScroll": true
}
},
{
"path": "product-detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/order",
"pages": [
{
"path": "detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/refund",
"pages": [
{
"path": "apply",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "history",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/test",
"pages": [
{
"path": "login",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/wallet",
"pages": [
{
"path": "list",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "detail",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "recharge",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
},
{
"root": "pages/human-face",
"pages": [
{
"path": "list",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
},
{
"path": "apply",
"style": {
"navigationBarTitleText": "",
"disableScroll": true
}
}
]
}
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "浦江小程序",
"navigationBarBackgroundColor": "#1777FF",
"backgroundColor": "#ecf4f9",
"navigationStyle": "custom"
},
"tabBar": {
"list": [
{
"pagePath": "pages/tabbar/home",
"text": "首页",
"iconPath": "static/tabbar/home.png",
"selectedIconPath": "static/tabbar/home-select.png"
},
{
"pagePath": "pages/tabbar/shop",
"text": "超市",
"iconPath": "static/tabbar/shop.png",
"selectedIconPath": "static/tabbar/shop-select.png"
},
{
"pagePath": "pages/tabbar/order",
"text": "订单",
"iconPath": "static/tabbar/order.png",
"selectedIconPath": "static/tabbar/order-select.png"
},
{
"pagePath": "pages/tabbar/my",
"text": "我的",
"iconPath": "static/tabbar/my.png",
"selectedIconPath": "static/tabbar/my-select.png"
}
]
}
}
+91 -81
View File
@@ -1,105 +1,115 @@
<script setup lang="ts">
import { ref, reactive, nextTick } from "vue";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { isEmpty } from "radash";
import { ref, reactive, nextTick } from "vue"
import { onLoad, onShow } from "@dcloudio/uni-app"
import { isEmpty } from "radash"
import { hooks, router, constant } from "@@/index";
import { faceApi } from "@@/api";
import { hooks, router, constant } from "@@/index"
import { faceApi } from "@@/api"
import { filePath } from "@@/utils/file"
const state = reactive<any>({
detailType: "add",
detailId: null,
detail: null,
header: {}
});
detailType: "add",
detailId: null,
detail: null,
header: {},
})
const applyForm = reactive<any>({
faceImg: [],
});
const uploadFileUrl = ref<any>("");
faceImg: [],
})
const uploadFileUrl = ref<any>("")
const applyFormRules = reactive<any>({
faceImg: [{ required: true, message: "请上传人脸图片" }],
});
faceImg: [{ required: true, message: "请上传人脸图片" }],
})
onLoad(async (options: any) => {
const { type, id } = options;
if (!isEmpty(type)) state.detailType = type;
if (!isEmpty(id)) state.detailId = id;
state.header = hooks.useDefaultHeader()
if (type === "edit") {
applyForm.faceImg = [];
uploadFileUrl.value = "";
await getDetail();
}
});
onShow(() => { });
const { type, id } = options
if (!isEmpty(type)) state.detailType = type
if (!isEmpty(id)) state.detailId = id
state.header = hooks.useDefaultHeader()
if (type === "edit") {
applyForm.faceImg = []
uploadFileUrl.value = ""
await getDetail()
}
})
onShow(() => {})
const getDetail = async () => {
if (isEmpty(state.detailId)) return;
const { data } = await faceApi.get({ id: state.detailId });
if (!isEmpty(data)) {
const img = filePath(data.faceImg)
applyForm.faceImg = [img]
uploadFileUrl.value = img
}
};
if (isEmpty(state.detailId)) return
const { data } = await faceApi.get({ id: state.detailId })
if (!isEmpty(data)) {
const img = filePath(data.faceImg)
applyForm.faceImg = [img]
uploadFileUrl.value = img
}
}
const beforeComplete = (uploadFile: any) => {
if (JSON.parse(uploadFile.data).code == 0) {
uploadFileUrl.value = JSON.parse(uploadFile.data).data.url;
return true;
} else {
uploadFileUrl.value = "";
return false;
}
};
if (JSON.parse(uploadFile.data).code == 0) {
uploadFileUrl.value = JSON.parse(uploadFile.data).data.url
return true
} else {
uploadFileUrl.value = ""
return false
}
}
const applyFormRef = ref<any>(null);
const applyFormRef = ref<any>(null)
const doSubmit = async () => {
applyFormRef.value.submit();
const { isPass } = applyFormRef.value.validate();
if (!isPass || !uploadFileUrl.value) return;
try {
uni.showLoading({ title: "提交中...", mask: false });
const { data, code }: any =
state.detailType == "edit"
? await faceApi.put({ faceImg: uploadFileUrl.value, id: state.detailId })
: await faceApi.create({ faceImg: uploadFileUrl.value });
if (code != 0) throw new Error();
uni.hideLoading();
uni.showToast({ title: "提交成功", icon: "none" });
router.back();
} catch (error) {
console.error(error);
uni.hideLoading();
}
};
applyFormRef.value.submit()
const { isPass } = applyFormRef.value.validate()
if (!isPass || !uploadFileUrl.value) return
try {
uni.showLoading({ title: "提交中...", mask: false })
const { data, code }: any =
state.detailType == "edit"
? await faceApi.put({ faceImg: uploadFileUrl.value, id: state.detailId })
: await faceApi.create({ faceImg: uploadFileUrl.value })
if (code != 0) throw new Error()
uni.hideLoading()
uni.showToast({ title: "提交成功", icon: "none" })
router.back()
} catch (error) {
console.error(error)
uni.hideLoading()
}
}
</script>
<template>
<crud-layout :title="state.detailId ? '修改人脸' : '人脸上传'" bg="/static/page/blue-bg.png">
<view class="h-30rpx" />
<view class="card p-x-30rpx p-y-40rpx">
<tm-form ref="applyFormRef" v-model="applyForm" :rules="applyFormRules" direction="vertical">
<tm-form-item name="faceImg" label="人脸图片" :required="false" :showBottom="false">
<view class="h-10rpx" />
<tm-upload-photo :header="state.header" :rangUrl="applyForm.faceImg[0]" :beforeComplete="beforeComplete"
v-model="applyForm.faceImg" :maxCount="1" :url="'/api/admin/sys-file/upload'" />
</tm-form-item>
</tm-form>
</view>
<view v-if="state.detailType != 'view'"
class="bg-#0094ff p-y-20rpx text-center rounded-40rpx m-x-30rpx m-t-60rpx sub-text-30 color-white!"
@tap="doSubmit">
{{ state.detailId ? "修改" : "提交" }}
</view>
</crud-layout>
<crud-layout :title="state.detailId ? '修改人脸' : '人脸上传'" bg="/static/page/blue-bg.png">
<view class="h-30rpx" />
<view class="card p-x-30rpx p-y-40rpx">
<tm-form ref="applyFormRef" v-model="applyForm" :rules="applyFormRules" direction="vertical">
<tm-form-item name="faceImg" label="人脸图片" :required="false" :showBottom="false">
<view class="h-10rpx" />
<tm-upload-photo
:maxFileSize="1024 * 1024"
:header="state.header"
:rangUrl="applyForm.faceImg[0]"
:beforeComplete="beforeComplete"
v-model="applyForm.faceImg"
:maxCount="1"
:url="'/api/admin/sys-file/upload'"
/>
</tm-form-item>
<view class="sub-text-20 c-red!">注:图片大小不超过1M</view>
</tm-form>
</view>
<view
v-if="state.detailType != 'view'"
class="bg-#0094ff p-y-20rpx text-center rounded-40rpx m-x-30rpx m-t-60rpx sub-text-30 color-white!"
@tap="doSubmit"
>
{{ state.detailId ? "修改" : "提交" }}
</view>
</crud-layout>
</template>
<style lang="scss" scoped>
:deep() {
.tmFormItemLabel {
padding-bottom: 10rpx !important;
}
.tmFormItemLabel {
padding-bottom: 10rpx !important;
}
}
</style>
+4
View File
@@ -15,6 +15,10 @@ const state = reactive<any>({
onLoad(() => {})
onShow(() => {
router.jump("/pages/tabbar/home")
uni.showToast({ title: "敬请期待", icon: "none", duration: 1000 })
return
if (pageRef.value) {
pageRef.value.reload(false)
}