Commit 0b53f038 by Lin

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

1 parent 565fafeb
......@@ -357,4 +357,11 @@ export function getLightChangeConfig(data) {
export function updateLightChangeConfig(data) {
data.method = `${path}servicecenter.short.course.config.submit`;
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
......@@ -154,10 +154,8 @@
</template>
<script>
import { getLightChangeConfig, updateLightChangeConfig } from "@api/serviceCentre";
import GlOssApi from "glsk-oss-jssdk";
import { getLightChangeConfig, importLightChangePhone, updateLightChangeConfig } from "@api/serviceCentre";
import { effectiveTypeOpt, punishTypeOpt } from "@/common/constants.js";
import { baseConfig } from "@/main";
export default {
props: {
......@@ -232,11 +230,6 @@ export default {
created() {
this.getSopConfigData();
},
mounted() {
this.GlOssApi = new GlOssApi({
baseConfig,
});
},
methods: {
validateNumber(field, min, max) {
let value = this.configData[field];
......@@ -289,16 +282,13 @@ export default {
this.$refs.formRef.validate((valid, invalidFields) => {
if (valid) {
const params = {
storePenetrationWeekly: this.configData.storePenetrationWeekly,
storePenetrationMonthly: this.configData.storePenetrationMonthly,
inspectionScore: this.configData.inspectionScore,
studyDay: this.configData.studyDay,
punishType: this.configData.punishType,
finishTime: this.configData.finishTime,
effectiveType: this.configData.effectiveType,
openFlag: this.configData.openFlag === "Y" ? 1 : 0,
phoneWhitelistFileUrl: this.configData.phoneWhitelistFileUrl,
staffList: [],
};
console.log(params, "params");
updateLightChangeConfig(params)
.then((res) => {
console.log(res, "updateLightChangeConfig");
......@@ -344,6 +334,7 @@ export default {
}
},
handleWhitelistFileChange(file) {
console.log(file, "file");
const fileInfo = file.raw;
if (!fileInfo)
return;
......@@ -370,22 +361,44 @@ export default {
};
this.whitelistFiles = [item];
const index = 0;
const success = (res) => {
this.$set(this.whitelistFiles[index], "fileUrl", res.aliyunAddress);
this.$set(this.whitelistFiles[index], "uploadProgress", 100);
this.configData.phoneWhitelistFileUrl = res.aliyunAddress;
};
const fail = () => {
const fail = (msg) => {
this.whitelistFiles = [];
this.configData.phoneWhitelistFileUrl = "";
this.$refs.whitelistUpload && this.$refs.whitelistUpload.clearFiles();
msg && this.$message.error(msg);
};
this.handleOssUpload(fileInfo, fileInfo.name, success, fail);
},
handleOssUpload(file, fileName, success, fail) {
const bucketName = "jinrong-huidan-test";
const fileType = fileName.substr(fileName.lastIndexOf(".") + 1);
this.GlOssApi.multipartUpload(file, success, fail, bucketName, fileType);
const onProcess = (progressEvent) => {
const total = progressEvent?.total || 0;
const loaded = progressEvent?.loaded || 0;
if (!total)
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() {
this.$message.error("最多可上传 1 个文件");
......
......@@ -147,7 +147,7 @@
</template>
<script>
import { getLightChangePage, switchLightChange } from "@api/serviceCentre";
import { getLightChangePage, importLightChangePhone, switchLightChange } from "@api/serviceCentre";
import dayjs from "dayjs";
import { mapActions, mapState } from "vuex";
import {
......@@ -339,8 +339,6 @@ export default {
try {
const params = await this.beforeSearchFn(2); // type = 2 表示导出 获取导出传参
params.currentPage = 1;
// params.method
// = "dj.api.smartcarlife.servicecenter.sop.detail.page.export";
params.method = "dj.api.smartcarlife.servicecenter.short.course.task.page.export";
const list = [
...this.dowloadList,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!