| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <template>
- <div>
- <a-button type="primary" class="inline-16" @click="allProduct" v-if="type=='upload'">一 键 全 选</a-button>
- <a-button type="primary" class="inline-16" @click="allProduct" v-else>一 键 删 除</a-button>
- <a-modal
- v-model:visible="progressVisible"
- class="custom-class"
- placement="right"
- width="500px"
- >
- <a-progress v-if="totalPage" :percent="Math.floor(progress / totalPage * 100)"></a-progress>
- </a-modal>
- </div>
- </template>
- <script setup>
- import listTemp from '@/components/listTemplate/index.vue'
- import normalTable from '@/template/normalTable/index.vue'
- import {ref, defineProps, defineEmits} from 'vue'
- import {Modal} from 'ant-design-vue'
- import Api from '@/api/api'
- import utils from '@/utils/utils'
- let emit = defineEmits(['handlePullApi','handleUploadApi','onSuccess','emitCallBack'])
- let props = defineProps({
- dataSize: {
- type:[Number,String],
- default:() => 200
- },
- total: {
- type:[Number,String],
- default:() => 0
- },
- type: {
- type:String,
- default:() => 'upload'
- },
- idName: {
- type: [Number,String]
- },
- dataType:{
- type:[String],
- default:() => '商品'
- },
- disabled:{
- type:[]
- },
- isEmit: {
- type: Object,
- default:() => false
- }
- })
- let totalPage = ref(0)
- let progress = ref(0)
- let progressVisible = ref(false)
- let deleteIds = ref([])
- let allProduct = () => {
- if (props.total > props.dataSize) {
- Modal.confirm({
- title:'提示',
- content:`总共有${props.total}个${props.dataType},是否确定${props.type == 'upload' ? '提交' : '删除'}`,
- async onOk() {
- /* 打断 */
- if (props.isEmit) {
- emit('emitCallBack',() => {
- progressVisible.value = true
- props.type == 'upload' ? totalPage.value = Math.ceil(props.total / props.dataSize) * 2 : totalPage.value = Math.ceil(props.total / props.dataSize)
- let totalPages = Math.ceil(props.total / props.dataSize)
- for (let index = 1; index <= totalPages; index++) {
- pullData(index)
- }
- })
- } else {
- progressVisible.value = true
- props.type == 'upload' ? totalPage.value = Math.ceil(total.value / props.dataSize) * 2 : totalPage.value = Math.ceil(props.total / props.dataSize)
- let totalPage = Math.ceil(props.total / props.dataSize)
- for (let index = 1; index <= totalPage; index++) {
- pullData(index)
- }
- }
- },
- })
- } else {
- Modal.confirm({
- title:'提示',
- content:`总共有${props.total}个${props.dataType},是否确定${props.type == 'upload' ? '提交' : '删除'}`,
- async onOk() {
- if (!props.total) return
- if(props.isEmit) {
- return emit('emitCallBack',async () => {
- let pullApi = {}
- /**
- * 暴露出去操作 修改拉取请求
- * @param pullApi - 拉取数据的请求接口
- */
- emit('handlePullApi',pullApi)
- pullApi.content.pageNumber = 1
- pullApi.content.pageSize = props.dataSize
- const res = await Api.requested(pullApi)
- if (props.type == 'upload') {
- let uploadApi = {}
- /**
- * 暴露出去操作 修改上传请求
- * @param1 uploadApi - 上传接口
- * @param2 res.data - 拉取的上传数据
- */
- emit('handleUploadApi',uploadApi,res.data)
- const res2 = await Api.requested(uploadApi)
- utils.message(res2,'添加成功',() => {
- emit('onSuccess',res2.data)
- })
- } else {
- deleteIds.value.push(...res.data.map(item => item[props.idName]))
- deleteOrderProduct(deleteIds.value)
- }
- })
- }
- let pullApi = {}
- /**
- * 暴露出去操作 修改拉取请求
- * @param pullApi - 拉取数据的请求接口
- */
- emit('handlePullApi',pullApi)
- pullApi.content.pageNumber = 1
- pullApi.content.pageSize = props.dataSize
- const res = await Api.requested(pullApi)
- if (props.type == 'upload') {
- let uploadApi = {}
- /**
- * 暴露出去操作 修改上传请求
- * @param1 uploadApi - 上传接口
- * @param2 res.data - 拉取的上传数据
- */
- emit('handleUploadApi',uploadApi,res.data)
- const res2 = await Api.requested(uploadApi)
- utils.message(res2,() => {
- emit('onSuccess',res2.data)
- })
- } else {
- deleteIds.value.push(...res.data.map(item => item[props.idName]))
- deleteOrderProduct(deleteIds.value)
- }
- },
- })
- }
- }
- /* 拉取数据 */
- let pullData = async (page) => {
- let pullApi = {}
- /**
- * 暴露出去操作 修改拉取请求
- * @param pullApi - 拉取数据的请求接口
- */
- emit('handlePullApi',pullApi)
- pullApi.content.pageNumber = page
- pullApi.content.pageSize = props.dataSize
- const res = await Api.requested(pullApi)
- progress.value++
- if (props.type == 'upload') {
- uploadData(res.data)
- if (progress.value >= totalPage.value) {
- emit('onSuccess')
- progressVisible.value = false
- progress.value = 0
- }
- } else {
- deleteIds.value.push(...res.data.map(item => item[props.idName]))
- if (progress.value >= totalPage.value) {
- deleteOrderProduct(deleteIds.value)
- progressVisible.value = false
- }
- }
- }
- /* 添加数据 */
- let uploadData = async (data) => {
- let uploadApi = {}
- /**
- * 暴露出去操作 修改上传请求
- * @param1 uploadApi - 上传接口
- * @param2 res.data - 拉取的上传数据
- */
- emit('handleUploadApi',uploadApi,data)
- const res = await Api.requested(uploadApi)
- progress.value++
- if (progress.value >= totalPage.value) {
- emit('onSuccess')
- progressVisible.value = false
- progress.value = 0
- }
- }
- </script>
- <style scoped>
- </style>
|