|
|
@@ -6,7 +6,6 @@
|
|
|
<CardLayout title="基础配置" :isShowWraning="false" :mandatory="false">
|
|
|
<el-form
|
|
|
ref="ruleFormRef"
|
|
|
- style="max-width: 600px"
|
|
|
label-width="auto"
|
|
|
:model="ruleForm"
|
|
|
:rules="formRules"
|
|
|
@@ -14,7 +13,7 @@
|
|
|
class="el-form-outer"
|
|
|
>
|
|
|
<el-form-item label="消息样式: " prop="messageType">
|
|
|
- <el-radio-group v-model="ruleForm.messageType" :disabled="isDisabled">
|
|
|
+ <el-radio-group v-model="ruleForm.messageType" :disabled="!disabled">
|
|
|
<el-radio :value="item.value" v-for="item in messageTypeOptions" :key="item.value"
|
|
|
>{{ item.label }}
|
|
|
</el-radio>
|
|
|
@@ -26,7 +25,7 @@
|
|
|
placeholder="请输入20字以内的消息标题"
|
|
|
maxlength="20"
|
|
|
show-word-limit
|
|
|
- :disabled="isDisabled"
|
|
|
+ :disabled="!disabled"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
<el-form-item
|
|
|
@@ -34,19 +33,23 @@
|
|
|
prop="bannerUrl"
|
|
|
v-if="ruleForm.messageType === MessageTypeEnum.BANNER"
|
|
|
>
|
|
|
- <img v-if="ruleForm.bannerUrl" :src="ruleForm.bannerUrl" class="avatar" />
|
|
|
<el-upload
|
|
|
- v-else
|
|
|
- class="avatar-uploader"
|
|
|
+ ref="upload"
|
|
|
+ v-model:file-list="fileList"
|
|
|
:action="actionUrl"
|
|
|
:headers="getHeaders()"
|
|
|
:data="{ bizType: 'PUSH_MESSAGE' }"
|
|
|
- :show-file-list="false"
|
|
|
:on-success="handleAvatarSuccess"
|
|
|
:before-upload="beforeAvatarUpload"
|
|
|
+ :limit="1"
|
|
|
+ list-type="picture-card"
|
|
|
+ :on-exceed="handleExceed"
|
|
|
+ :on-preview="handlePictureCardPreview"
|
|
|
+ :disabled="!disabled"
|
|
|
>
|
|
|
<el-icon class="avatar-uploader-icon"><Plus /></el-icon>
|
|
|
</el-upload>
|
|
|
+ <span class="tip-message">支持格式:.jpg、.jpeg、.png,文件不超过 20MB,建议上传 4:3 比例的图片!</span>
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="推送渠道: " prop="pushChannel">
|
|
|
@@ -56,7 +59,7 @@
|
|
|
:key="item.value"
|
|
|
:value="item.value"
|
|
|
:label="item.label"
|
|
|
- :disabled="isDisabled"
|
|
|
+ :disabled="!disabled"
|
|
|
/>
|
|
|
</el-checkbox-group>
|
|
|
</el-form-item>
|
|
|
@@ -67,24 +70,30 @@
|
|
|
placeholder="请选择失效时间"
|
|
|
format="YYYY/MM/DD hh:mm:ss"
|
|
|
value-format="YYYY-MM-DD hh:mm:ss"
|
|
|
- :disabled="isDisabled"
|
|
|
+ :disabled="!disabled"
|
|
|
+ :disabled-date="disabledDate"
|
|
|
/>
|
|
|
+ <span class="tip-message">请注意:超过该日期后,【APP/PC 主页】将不再弹出消息!</span>
|
|
|
</el-form-item>
|
|
|
<PushObject
|
|
|
ref="childFromRef"
|
|
|
:recipientType="ruleForm.recipientType"
|
|
|
:userGroupList="ruleForm.userGroupList"
|
|
|
:customUserList="ruleForm.customUserList"
|
|
|
- :disabled="isDisabled"
|
|
|
+ :disabled="!disabled"
|
|
|
/>
|
|
|
</el-form>
|
|
|
</CardLayout>
|
|
|
+ <el-dialog v-model="dialogVisible">
|
|
|
+ <img w-full :src="dialogImageUrl" alt="Preview Image" />
|
|
|
+ </el-dialog>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
- import { ref, watch, computed, unref } from 'vue';
|
|
|
- import type { FormInstance, FormProps, FormRules, UploadProps } from 'element-plus';
|
|
|
- import { ElMessage } from 'element-plus';
|
|
|
+import { ref, watch, computed, unref } from 'vue'
|
|
|
+ import { useRoute } from 'vue-router'
|
|
|
+ import type { FormInstance, FormProps, FormRules, UploadProps, UploadUserFile, UploadInstance, UploadRawFile } from 'element-plus';
|
|
|
+ import { ElMessage, genFileId } from 'element-plus';
|
|
|
import { Plus } from '@element-plus/icons-vue';
|
|
|
import PushObject from '../../components/PushObject.vue';
|
|
|
import CardLayout from './CardLayout.vue';
|
|
|
@@ -93,6 +102,7 @@
|
|
|
import urlJoin from 'url-join';
|
|
|
import { useGlobSetting } from '@/hooks/setting';
|
|
|
import { getHeaders } from '@/utils/http/axios';
|
|
|
+ import { isEmpty } from 'lodash-es';
|
|
|
|
|
|
const { urlPrefix } = useGlobSetting();
|
|
|
interface Props {
|
|
|
@@ -100,6 +110,8 @@
|
|
|
isDisabled: boolean;
|
|
|
}
|
|
|
const props = defineProps<Props>();
|
|
|
+ const route = useRoute();
|
|
|
+ const disabled = computed(() => props.isDisabled === false || route.query.viewModel === 'edit')
|
|
|
const labelPosition = ref<FormProps['labelPosition']>('left');
|
|
|
const childFromRef = ref<InstanceType<typeof PushObject>>();
|
|
|
const actionUrl = computed(() => {
|
|
|
@@ -130,12 +142,21 @@
|
|
|
userGroupList: [],
|
|
|
customUserList: [],
|
|
|
});
|
|
|
+ const fileList = ref<UploadUserFile[]>([]);
|
|
|
|
|
|
watch(
|
|
|
() => props.dataSoure,
|
|
|
(value) => {
|
|
|
if (value) {
|
|
|
ruleForm.value = { ...value };
|
|
|
+ if (!isEmpty(value.bannerUrl)) {
|
|
|
+ fileList.value = [
|
|
|
+ {
|
|
|
+ name: '',
|
|
|
+ url: value.bannerUrl
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
{
|
|
|
@@ -150,45 +171,69 @@
|
|
|
if (!ruleFormRef.value) return;
|
|
|
try {
|
|
|
const isSuccess = await ruleFormRef.value.validate();
|
|
|
- if (isSuccess) {
|
|
|
- const childValue = childFromRef.value!.getChildValue();
|
|
|
- childFromRef.value!.submitForm().then((res) => {
|
|
|
- isValidate.value = res;
|
|
|
- });
|
|
|
-
|
|
|
- const basicInfo = { ...unref(ruleForm) } as RuleFormAdd;
|
|
|
-
|
|
|
- if (childValue) {
|
|
|
- basicInfo.recipientType = childValue.recipientType!;
|
|
|
- basicInfo.userGroupList = childValue.userGroupList!;
|
|
|
- basicInfo.customUserList = childValue.customUserList!;
|
|
|
- }
|
|
|
- return basicInfo;
|
|
|
- }
|
|
|
+ return isSuccess;
|
|
|
} catch (error) {
|
|
|
ElMessage.error('请完善信息填写');
|
|
|
throw error;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+
|
|
|
const handleAvatarSuccess: UploadProps['onSuccess'] = (response) => {
|
|
|
// 注意,这里 response 是 没有被拦截处理
|
|
|
ruleForm.value.bannerUrl = response.data.url;
|
|
|
- console.log(ruleForm.value);
|
|
|
+
|
|
|
+
|
|
|
};
|
|
|
|
|
|
+ // 上传前限制
|
|
|
const beforeAvatarUpload: UploadProps['beforeUpload'] = (rawFile) => {
|
|
|
- if (!['image/jpeg', 'image/png'].includes(rawFile.type)) {
|
|
|
- ElMessage.error('Avatar picture must be JPG format!');
|
|
|
+ if (!['image/jpeg', 'image/png', 'image/jpg'].includes(rawFile.type)) {
|
|
|
+ ElMessage.error('文件格式仅支持:.jpg, .jpeg, .png');
|
|
|
return false;
|
|
|
- } else if (rawFile.size / 1024 / 1024 > 5) {
|
|
|
- ElMessage.error('Avatar picture size can not exceed 2MB!');
|
|
|
+ } else if (rawFile.size / 1024 / 1024 > 20) {
|
|
|
+ ElMessage.error('文件不支持超过 20MB!');
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
};
|
|
|
|
|
|
- defineExpose({ validate });
|
|
|
+ // 图片预览
|
|
|
+ const dialogImageUrl = ref('')
|
|
|
+ const dialogVisible = ref(false)
|
|
|
+ const handlePictureCardPreview: UploadProps['onPreview'] = (uploadFile) => {
|
|
|
+ dialogImageUrl.value = uploadFile.url!
|
|
|
+ dialogVisible.value = true
|
|
|
+ }
|
|
|
+
|
|
|
+ const upload = ref<UploadInstance>()
|
|
|
+ const handleExceed: UploadProps['onExceed'] = (files) => {
|
|
|
+ upload.value!.clearFiles()
|
|
|
+ const file = files[0] as UploadRawFile
|
|
|
+ file.uid = genFileId()
|
|
|
+ upload.value!.handleStart(file)
|
|
|
+ }
|
|
|
+
|
|
|
+ const buildFromData = () => {
|
|
|
+ const childValue = childFromRef.value!.getChildValue();
|
|
|
+ childFromRef.value!.submitForm().then((res) => {
|
|
|
+ isValidate.value = res;
|
|
|
+ });
|
|
|
+
|
|
|
+ const basicInfo = { ...unref(ruleForm) } as RuleFormAdd;
|
|
|
+ if (childValue) {
|
|
|
+ basicInfo.recipientType = childValue.recipientType!;
|
|
|
+ basicInfo.userGroupList = childValue.userGroupList!;
|
|
|
+ basicInfo.customUserList = childValue.customUserList!;
|
|
|
+ }
|
|
|
+ return basicInfo;
|
|
|
+ };
|
|
|
+
|
|
|
+ const disabledDate = (time: Date) => {
|
|
|
+ return time.getTime() < Date.now()
|
|
|
+ }
|
|
|
+
|
|
|
+ defineExpose({ validate, buildFromData });
|
|
|
</script>
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
@@ -217,4 +262,8 @@
|
|
|
height: 58px;
|
|
|
text-align: center;
|
|
|
}
|
|
|
+
|
|
|
+ .tip-message {
|
|
|
+ margin-left: 20px;
|
|
|
+ }
|
|
|
</style>
|