Commit 0b53f038 by Lin

feat: 新增手机号导入功能,优化短课程配置组件,提升用户体验和代码可读性

1 parent 565fafeb
...@@ -357,4 +357,11 @@ export function getLightChangeConfig(data) { ...@@ -357,4 +357,11 @@ export function getLightChangeConfig(data) {
export function updateLightChangeConfig(data) { export function updateLightChangeConfig(data) {
data.method = `${path}servicecenter.short.course.config.submit`; data.method = `${path}servicecenter.short.course.config.submit`;
return request(data, RequestMethods.POST); return request(data, RequestMethods.POST);
}
// 轻改-短课程配置-手机号导入
export function importLightChangePhone(data) {
data.method = `${path}servicecenter.short.course.phone.import`;
// 文件参数不参与签名拼接(参考 importProfit)
return request(data, RequestMethods.POST, ["file"]);
} }
\ No newline at end of file \ No newline at end of file
...@@ -154,10 +154,8 @@ ...@@ -154,10 +154,8 @@
</template> </template>
<script> <script>
import { getLightChangeConfig, updateLightChangeConfig } from "@api/serviceCentre"; import { getLightChangeConfig, importLightChangePhone, updateLightChangeConfig } from "@api/serviceCentre";
import GlOssApi from "glsk-oss-jssdk";
import { effectiveTypeOpt, punishTypeOpt } from "@/common/constants.js"; import { effectiveTypeOpt, punishTypeOpt } from "@/common/constants.js";
import { baseConfig } from "@/main";
export default { export default {
props: { props: {
...@@ -232,11 +230,6 @@ export default { ...@@ -232,11 +230,6 @@ export default {
created() { created() {
this.getSopConfigData(); this.getSopConfigData();
}, },
mounted() {
this.GlOssApi = new GlOssApi({
baseConfig,
});
},
methods: { methods: {
validateNumber(field, min, max) { validateNumber(field, min, max) {
let value = this.configData[field]; let value = this.configData[field];
...@@ -289,16 +282,13 @@ export default { ...@@ -289,16 +282,13 @@ export default {
this.$refs.formRef.validate((valid, invalidFields) => { this.$refs.formRef.validate((valid, invalidFields) => {
if (valid) { if (valid) {
const params = { const params = {
storePenetrationWeekly: this.configData.storePenetrationWeekly,
storePenetrationMonthly: this.configData.storePenetrationMonthly,
inspectionScore: this.configData.inspectionScore,
studyDay: this.configData.studyDay,
punishType: this.configData.punishType, punishType: this.configData.punishType,
finishTime: this.configData.finishTime, finishTime: this.configData.finishTime,
effectiveType: this.configData.effectiveType, effectiveType: this.configData.effectiveType,
openFlag: this.configData.openFlag === "Y" ? 1 : 0, openFlag: this.configData.openFlag === "Y" ? 1 : 0,
phoneWhitelistFileUrl: this.configData.phoneWhitelistFileUrl, staffList: [],
}; };
console.log(params, "params");
updateLightChangeConfig(params) updateLightChangeConfig(params)
.then((res) => { .then((res) => {
console.log(res, "updateLightChangeConfig"); console.log(res, "updateLightChangeConfig");
...@@ -344,6 +334,7 @@ export default { ...@@ -344,6 +334,7 @@ export default {
} }
}, },
handleWhitelistFileChange(file) { handleWhitelistFileChange(file) {
console.log(file, "file");
const fileInfo = file.raw; const fileInfo = file.raw;
if (!fileInfo) if (!fileInfo)
return; return;
...@@ -370,22 +361,44 @@ export default { ...@@ -370,22 +361,44 @@ export default {
}; };
this.whitelistFiles = [item]; this.whitelistFiles = [item];
const index = 0; const index = 0;
const success = (res) => { const fail = (msg) => {
this.$set(this.whitelistFiles[index], "fileUrl", res.aliyunAddress);
this.$set(this.whitelistFiles[index], "uploadProgress", 100);
this.configData.phoneWhitelistFileUrl = res.aliyunAddress;
};
const fail = () => {
this.whitelistFiles = []; this.whitelistFiles = [];
this.configData.phoneWhitelistFileUrl = ""; this.configData.phoneWhitelistFileUrl = "";
this.$refs.whitelistUpload && this.$refs.whitelistUpload.clearFiles(); this.$refs.whitelistUpload && this.$refs.whitelistUpload.clearFiles();
msg && this.$message.error(msg);
}; };
this.handleOssUpload(fileInfo, fileInfo.name, success, fail);
}, const onProcess = (progressEvent) => {
handleOssUpload(file, fileName, success, fail) { const total = progressEvent?.total || 0;
const bucketName = "jinrong-huidan-test"; const loaded = progressEvent?.loaded || 0;
const fileType = fileName.substr(fileName.lastIndexOf(".") + 1); if (!total)
this.GlOssApi.multipartUpload(file, success, fail, bucketName, fileType); return;
const percent = Math.min(99, Math.max(0, Math.floor((loaded / total) * 100)));
this.$set(this.whitelistFiles[index], "uploadProgress", percent);
};
importLightChangePhone({
file: fileInfo,
onProcess,
cancelFun: this.whitelistFiles[index].cancelAxios,
})
.then((res) => {
this.$set(this.whitelistFiles[index], "uploadProgress", 100);
// 尝试从返回值中取可预览的 url(不同后端可能字段不同)
const url = (typeof res === "string" && /^https?:\/\//.test(res))
? res
: (res?.fileUrl || res?.url || res?.aliyunAddress || "");
if (url) {
this.$set(this.whitelistFiles[index], "fileUrl", url);
this.configData.phoneWhitelistFileUrl = url;
}
this.$message.success("上传成功");
})
.catch((err) => {
console.error(err);
fail(err?.message || "上传失败");
});
}, },
handleWhitelistExceed() { handleWhitelistExceed() {
this.$message.error("最多可上传 1 个文件"); this.$message.error("最多可上传 1 个文件");
......
...@@ -147,7 +147,7 @@ ...@@ -147,7 +147,7 @@
</template> </template>
<script> <script>
import { getLightChangePage, switchLightChange } from "@api/serviceCentre"; import { getLightChangePage, importLightChangePhone, switchLightChange } from "@api/serviceCentre";
import dayjs from "dayjs"; import dayjs from "dayjs";
import { mapActions, mapState } from "vuex"; import { mapActions, mapState } from "vuex";
import { import {
...@@ -339,8 +339,6 @@ export default { ...@@ -339,8 +339,6 @@ export default {
try { try {
const params = await this.beforeSearchFn(2); // type = 2 表示导出 获取导出传参 const params = await this.beforeSearchFn(2); // type = 2 表示导出 获取导出传参
params.currentPage = 1; params.currentPage = 1;
// params.method
// = "dj.api.smartcarlife.servicecenter.sop.detail.page.export";
params.method = "dj.api.smartcarlife.servicecenter.short.course.task.page.export"; params.method = "dj.api.smartcarlife.servicecenter.short.course.task.page.export";
const list = [ const list = [
...this.dowloadList, ...this.dowloadList,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!