Commit ac0b120f9a29e19a84e8c82c4d5e2d7f116ed7f5

Authored by 杨泽宇
1 parent 0a0780aa

error msg, textarea add br, upload tips

src/css/test.css
... ... @@ -22,6 +22,10 @@
22 22 color: #4A90E2;
23 23 font-size: 20px;
24 24 }
  25 +.diy-error {
  26 + color: #D11244;
  27 + font-size: 20px;
  28 +}
25 29 .diy-danger {
26 30 color: #D11244; margin-left: 10px;
27 31 }
... ...
src/html/index.html
... ... @@ -73,24 +73,37 @@
73 73 :before-remove="handleRemove" :disabled="btnDisabled" :show-file-list="false">
74 74 <el-button size="small" type="primary" :disabled="btnDisabled" class="diy-button width-190 bg-blue">选择文件
75 75 </el-button>
  76 + <el-tooltip placement="top">
  77 + <template #content>
  78 + <p>1)可上传的音频格式:mp3/flac/wav/ogg/mpg/wma/aac/acc/m4a。</p>
  79 + <p>2)音频上传过程中,请勿离开此页面或者刷新此页面,否则会导致音频上传任务失败!</p>
  80 + <p>3)音频文件大小上限:500M,数量上限:1。</p>
  81 + </template>
  82 + <el-button type="text" size="mini" class="title-small">上传须知</el-button>
  83 + </el-tooltip>
76 84 </el-upload>
77 85 <!-- <span class="diy-danger">{{msgText}}</span> -->
78 86 </el-form-item>
79   - <el-form-item class="diy-flex-50" label="上传须知">
  87 + <!-- <el-form-item class="diy-flex-50" label="上传须知"> -->
80 88 <!-- <el-button class="diy-button width-140 bg-white">查看</el-button> -->
81   - <el-tooltip placement="top">
  89 + <!-- <el-tooltip placement="top">
82 90 <template #content>
83   - <p>1)可上传的音频格式:mp3/flac/wav/ogg/mpg/wma/aac/acc/m4a</p>
  91 + <p>1)可上传的音频格式:mp3/flac/wav/ogg/mpg/wma/aac/acc/m4a</p>
84 92 <p>2)音频上传过程中,请勿离开此页面或者刷新此页面,否则会导致音频上传任务失败!</p>
85 93 <p>3)音频文件大小上限:500M,数量上限:1。</p>
86 94 </template>
87   - <el-button class="diy-button width-140 bg-white">查看</el-button>
88   - </el-form-item>
  95 + <el-button class="diy-button width-140 bg-white">查看</el-button> -->
  96 + <!-- </el-form-item> -->
89 97 <el-divider></el-divider>
90 98 <el-form-item class="diy-flex-50 diy-text-left">
91   - <div class="diy-tip">{{form.audioFile?.name}} </div>
92   - <div class="diy-tip" v-if="percent > 0 && percent < 100"> 已上传{{Math.ceil(percent)}}%,请耐心等待……</div>
93   - <div class="diy-tip" v-if="percent == 100"> 上传完成</div>
  99 + <div>
  100 + <div class="diy-tip">{{form.audioFile?.name}} </div>
  101 + <div class="diy-tip" v-if="percent > 0 && percent < 100"> 已上传{{Math.ceil(percent)}}%,请耐心等待……</div>
  102 + <div class="diy-tip" v-if="percent == 100"> 上传完成</div>
  103 + </div>
  104 + <div v-if="errorMsg">
  105 + <div class="diy-error">{{errorMsg}}</div>
  106 + </div>
94 107 </el-form-item>
95 108 <el-form-item class="diy-flex-50 diy-text-right">
96 109 <el-button @click="reset" class="diy-button width-140 bg-white" v-if="form.channelId == 1279">取消</el-button>
... ...
src/js/audios.js
... ... @@ -82,6 +82,7 @@ const Audio = {
82 82 "只能上传一个mp3/flac/wav/ogg/mpg/wma/aac/acc/m4a格式的音频文件,且不超过500mb。上传过程中请勿刷新页面。",
83 83 percent: 0,
84 84 curFile: "",
  85 + errorMsg: "",
85 86 };
86 87 },
87 88 methods: {
... ... @@ -124,6 +125,7 @@ const Audio = {
124 125 // 文件数量超上限响应
125 126 exceed(e, d) {
126 127 this.$message.error("只能上传一个文件");
  128 + this.errorMsg = "只能上传一个文件";
127 129 },
128 130 // 表单重置按钮响应
129 131 reset() {
... ... @@ -137,6 +139,7 @@ const Audio = {
137 139 // 文件移除响应,暂未启用
138 140 handleRemove(file, list) {
139 141 if (this.percent < 100) {
  142 + this.errorMsg = "上传中的文件不可删除";
140 143 this.$message({
141 144 type: "error",
142 145 duration: 5000,
... ... @@ -244,26 +247,57 @@ const Audio = {
244 247 params: all.parseQueryString(apiStringSignDone),
245 248 })
246 249 .then((res) => {
247   - let apiComplete =
248   - all.secretUrls.base + all.secretUrls.callback;
249   - let apiStringSignComplete = all.signFunction(
250   - apiComplete,
251   - that.getParamsList({
252   - ...fileBaseObj,
253   - ...fileSaveObj,
254   - ...{ timestamp: that.getTimeStamp() },
255   - })
256   - );
257   - return all.request({
258   - url: apiComplete,
259   - method: "get",
260   - params: all.parseQueryString(apiStringSignComplete),
261   - });
  250 + if (
  251 + res &&
  252 + res.data &&
  253 + res.data.errorCode &&
  254 + res.data.errorCode != 0
  255 + ) {
  256 + that.errorMsg = "系统错误,请联系管理员";
  257 + // that.reset();
  258 + this.submitDisabled = false;
  259 + this.btnDisabled = false;
  260 + return false;
  261 + } else {
  262 + let apiComplete =
  263 + all.secretUrls.base + all.secretUrls.callback;
  264 + let apiStringSignComplete = all.signFunction(
  265 + apiComplete,
  266 + that.getParamsList({
  267 + ...fileBaseObj,
  268 + ...fileSaveObj,
  269 + ...{ timestamp: that.getTimeStamp() },
  270 + })
  271 + );
  272 + return all.request({
  273 + url: apiComplete,
  274 + method: "get",
  275 + params: all.parseQueryString(apiStringSignComplete),
  276 + });
  277 + }
262 278 })
263 279 .then((data) => {
264   - that.form.audioId = data.data.data.obj;
265   - that.percent = 100;
266   - that.postCms();
  280 + if (
  281 + data &&
  282 + data.data &&
  283 + data.data.data &&
  284 + data.data.data.obj
  285 + ) {
  286 + that.form.audioId = data.data.data.obj;
  287 + that.percent = 100;
  288 + that.postCms();
  289 + } else {
  290 + that.errorMsg = "系统错误,请联系管理员";
  291 + // that.reset()
  292 + this.submitDisabled = false;
  293 + this.btnDisabled = false;
  294 + }
  295 + })
  296 + .catch((error) => {
  297 + that.errorMsg = error ? error : "系统错误,请联系管理员";
  298 + // that.reset();
  299 + this.submitDisabled = false;
  300 + this.btnDisabled = false;
267 301 });
268 302 },
269 303 };
... ... @@ -284,11 +318,15 @@ const Audio = {
284 318 })
285 319 .then((n) => {
286 320 if (!this.token) {
287   - this.$message({
288   - type: "error",
289   - message: "鉴权失败",
290   - duration: 5000,
291   - });
  321 + // this.$message({
  322 + // type: "error",
  323 + // message: "鉴权失败",
  324 + // duration: 5000,
  325 + // });
  326 + this.errorMsg = "鉴权失败";
  327 + // this.reset();
  328 + this.submitDisabled = false;
  329 + this.btnDisabled = false;
292 330 return false;
293 331 }
294 332 fileBaseObj.md5 = n;
... ... @@ -323,24 +361,29 @@ const Audio = {
323 361 fileWholeObj.subscription =
324 362 fileWholeObj.observable.subscribe(observer);
325 363 } else {
326   - this.reset();
327   - this.$message({
328   - type: "error",
329   - duration: 0,
330   - message: "未知错误,请联系管理员。",
331   - });
  364 + if (
  365 + res &&
  366 + res.data &&
  367 + res.data.errorCode &&
  368 + res.data.errorCode != 0
  369 + ) {
  370 + this.errorMsg = "系统错误,请联系管理员";
  371 + // this.reset();
  372 + this.submitDisabled = false;
  373 + this.btnDisabled = false;
  374 + }
332 375 }
333 376 })
334 377 .catch((error) => {
335   - this.$message({
336   - type: "error",
337   - message: error,
338   - duration: 0,
339   - });
  378 + this.errorMsg = error ? error : "系统错误,请联系管理员";
  379 + // this.reset()
  380 + this.submitDisabled = false;
  381 + this.btnDisabled = false;
340 382 });
341 383 }
342 384 } else {
343   - this.$message.error("请检查表单内容");
  385 + // this.$message.error("请检查表单内容");
  386 + this.errorMsg = '请检查表单内容'
344 387 this.submitDisabled = false;
345 388 this.btnDisabled = false;
346 389 return false;
... ... @@ -412,7 +455,7 @@ const Audio = {
412 455 },
413 456 // cms接口提交videoId和表单内容
414 457 postCms() {
415   - this.form.lyric = this.form.lyric ? this.form.lyric.trim() : "";
  458 + this.form.lyric = this.addBr(this.form.lyric)
416 459 all
417 460 .request({
418 461 // url: "http://cmstest.cnlive.com:8768/contentApi/audioSave",
... ... @@ -429,7 +472,7 @@ const Audio = {
429 472 .then((res) => {
430 473 if (res.data) {
431 474 setTimeout(() => {
432   - // console.log("jump");
  475 + // console.log("jump success");
433 476 window.location.replace("./success.html");
434 477 }, 1000);
435 478 } else {
... ... @@ -466,7 +509,23 @@ const Audio = {
466 509 // 选择上传文件
467 510 getMp3(file) {
468 511 this.form.audioFile = file;
  512 + this.errorMsg = "";
469 513 },
  514 + // textarea换行转br
  515 + addBr(str) {
  516 + var reg = new RegExp("\r\n","g");
  517 + var regr = new RegExp("\r","g");
  518 + var regn = new RegExp("\n","g");
  519 + if(str) {
  520 + str = str.trim()
  521 + str = str.replace(regr,"<br/>")
  522 + str = str.replace(regn,"<br/>")
  523 + str = str.replace(reg,"<br/>")
  524 + } else {
  525 + str = ''
  526 + }
  527 + return str
  528 + }
470 529 },
471 530 };
472 531  
... ...
src/js/config.js
... ... @@ -108,7 +108,7 @@ const validateVideoSize = function (curSize) {
108 108 const validateNameLength = function (name) {
109 109 return new Promise((resolve, reject) => {
110 110 if (name.length < 1 || name.length > 100) {
111   - reject("文件名称最小长度为2,上限长度为100!");
  111 + reject("文件名称最小长度为1,上限长度为100!");
112 112 } else {
113 113 resolve("名字可以");
114 114 }
... ...
webpack.config.js
... ... @@ -11,7 +11,7 @@ module.exports = {
11 11 entry: path.join(__dirname, "src", "/js/audios.js"), //__dirname指的是当前目录,是目录形成绝对路径
12 12 output: {
13 13 //输入的文件名
14   - filename: "cloak.js",
  14 + filename: "br.js",
15 15 // filename: '[name].[hash:7].js',
16 16 publicPath: "/",
17 17 //输入的路径 webpack会自动打包生成
... ... @@ -25,7 +25,7 @@ module.exports = {
25 25 //文件中找到的路径
26 26 template: path.join(__dirname, "src", "html/index.html"),
27 27 //打包输出的路径
28   - filename: "cloak.html",
  28 + filename: "br.html",
29 29 }),
30 30 new CleanWebpackPlugin(),
31 31 new JavaScriptObfuscator(
... ...