add elasticsearch progress

master
Chopper 2021-08-12 02:17:28 +08:00
parent 02bf570f08
commit 682bd13b6e
2 changed files with 43 additions and 4 deletions

View File

@ -401,6 +401,11 @@ export const createIndex = () => {
return getRequest(`/elasticsearch`); return getRequest(`/elasticsearch`);
}; };
// 初始化商品索引
export const getProgress = () => {
return getRequest(`/elasticsearch/progress`);
};
// 分页查询自定义分词 // 分页查询自定义分词
export const getCustomWordsPage = (params) => { export const getCustomWordsPage = (params) => {
return getRequest(`/manager/custom-words`, params); return getRequest(`/manager/custom-words`, params);

View File

@ -56,13 +56,15 @@
<div class="label-btns"> <div class="label-btns">
<Button type="primary" @click="submit('formValidate')"></Button> <Button type="primary" @click="submit('formValidate')"></Button>
<Button type="primary" style="margin-left: 100px" @click="createIndex()"></Button> <Button type="primary" style="margin-left: 100px" @click="createIndex()"></Button>
<div class="progress-item" v-if="showProgress">
<i-progress :percent="progressVal"></i-progress>
</div>
</div> </div>
</Form> </Form>
</div> </div>
</template> </template>
<script> <script>
import { setSetting,createIndex } from "@/api/index"; import { setSetting,createIndex,getProgress } from "@/api/index";
import { handleSubmit } from "./validate"; import { handleSubmit } from "./validate";
export default { export default {
props: ["res", "type"], props: ["res", "type"],
@ -77,6 +79,9 @@ export default {
originalPictureWidth: "0", originalPictureWidth: "0",
originalPictureHeight: "0", originalPictureHeight: "0",
}, },
progressVal: 0,
showProgress: false,
intervalProgress: null,
ruleValidate: {} // ruleValidate: {} //
}; };
}, },
@ -96,10 +101,39 @@ export default {
createIndex().then((res) => { createIndex().then((res) => {
if (res.success) { if (res.success) {
this.$Message.success("开始生成!"); this.$Message.success("开始生成!");
} else { this.showProgress = true;
this.$Message.error("服务器异常!"); setTimeout(() => {
this.intervalProgress = setInterval(()=> {
getProgress().then(resp => {
let progressResult = resp.result
if (progressResult !=null && progressResult.flag === 0) {
clearInterval(this.intervalProgress);
this.showProgress = false;
this.$Message.success("生成成功!");
} else {
this.progressVal = Math.floor((progressResult.processed / progressResult.total) * 100);
}
});
}, 1000);
}, 10000);
} else if (res.code === 100000) {
this.showProgress = true;
this.intervalProgress = setInterval(()=> {
getProgress().then(resp => {
let progressResult = resp.result
if (progressResult !=null && progressResult.flag === 0) {
clearInterval(this.intervalProgress);
this.showProgress = false;
this.$Message.success("生成成功!");
} else {
this.progressVal = Math.floor((progressResult.processed / progressResult.total) * 100);
}
});
}, 1000);
} }
}); });
}, },
// //
setupSetting() { setupSetting() {