mirror of
				https://gitee.com/hhyykk/ipms-sjy-ui.git
				synced 2025-11-04 04:08:44 +08:00 
			
		
		
		
	feat: 完事秒杀时段管理
This commit is contained in:
		@@ -3,9 +3,8 @@ import request from '@/config/axios'
 | 
				
			|||||||
export interface SeckillConfigVO {
 | 
					export interface SeckillConfigVO {
 | 
				
			||||||
  id: number
 | 
					  id: number
 | 
				
			||||||
  name: string
 | 
					  name: string
 | 
				
			||||||
  startTime: Date
 | 
					  startTime: string
 | 
				
			||||||
  endTime: Date
 | 
					  endTime: string
 | 
				
			||||||
  seckillActivityCount: number
 | 
					 | 
				
			||||||
  picUrl: string
 | 
					  picUrl: string
 | 
				
			||||||
  status: number
 | 
					  status: number
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -30,6 +29,15 @@ export const updateSeckillConfig = async (data: SeckillConfigVO) => {
 | 
				
			|||||||
  return await request.put({ url: '/promotion/seckill-config/update', data })
 | 
					  return await request.put({ url: '/promotion/seckill-config/update', data })
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 修改时段配置状态
 | 
				
			||||||
 | 
					export const updateSeckillConfigStatus = (id: number, status: number) => {
 | 
				
			||||||
 | 
					  const data = {
 | 
				
			||||||
 | 
					    id,
 | 
				
			||||||
 | 
					    status
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  return request.put({ url: '/promotion/seckill-config/update-status', data: data })
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 删除秒杀时段配置
 | 
					// 删除秒杀时段配置
 | 
				
			||||||
export const deleteSeckillConfig = async (id: number) => {
 | 
					export const deleteSeckillConfig = async (id: number) => {
 | 
				
			||||||
  return await request.delete({ url: '/promotion/seckill-config/delete?id=' + id })
 | 
					  return await request.delete({ url: '/promotion/seckill-config/delete?id=' + id })
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,9 +8,8 @@
 | 
				
			|||||||
  </Dialog>
 | 
					  </Dialog>
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
<script lang="ts" name="SeckillConfigForm" setup>
 | 
					<script lang="ts" name="SeckillConfigForm" setup>
 | 
				
			||||||
import { cloneDeep } from 'lodash-es'
 | 
					 | 
				
			||||||
import * as SeckillConfigApi from '@/api/mall/promotion/seckill/seckillConfig'
 | 
					import * as SeckillConfigApi from '@/api/mall/promotion/seckill/seckillConfig'
 | 
				
			||||||
import { allSchemas, format, rules } from './seckillConfig.data'
 | 
					import { allSchemas, rules } from './seckillConfig.data'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const { t } = useI18n() // 国际化
 | 
					const { t } = useI18n() // 国际化
 | 
				
			||||||
const message = useMessage() // 消息弹窗
 | 
					const message = useMessage() // 消息弹窗
 | 
				
			||||||
@@ -31,9 +30,6 @@ const open = async (type: string, id?: number) => {
 | 
				
			|||||||
    formLoading.value = true
 | 
					    formLoading.value = true
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      const data = await SeckillConfigApi.getSeckillConfig(id)
 | 
					      const data = await SeckillConfigApi.getSeckillConfig(id)
 | 
				
			||||||
      const info = cloneDeep(data)
 | 
					 | 
				
			||||||
      data.startTime = format(info.startTime)
 | 
					 | 
				
			||||||
      data.endTime = format(info.endTime)
 | 
					 | 
				
			||||||
      formRef.value.setValues(data)
 | 
					      formRef.value.setValues(data)
 | 
				
			||||||
    } finally {
 | 
					    } finally {
 | 
				
			||||||
      formLoading.value = false
 | 
					      formLoading.value = false
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,15 +29,17 @@
 | 
				
			|||||||
        total: tableObject.total
 | 
					        total: tableObject.total
 | 
				
			||||||
      }"
 | 
					      }"
 | 
				
			||||||
    >
 | 
					    >
 | 
				
			||||||
      <template #startTime="{ row }">
 | 
					 | 
				
			||||||
        {{ format(row.startTime) }}
 | 
					 | 
				
			||||||
      </template>
 | 
					 | 
				
			||||||
      <template #endTime="{ row }">
 | 
					 | 
				
			||||||
        {{ format(row.endTime) }}
 | 
					 | 
				
			||||||
      </template>
 | 
					 | 
				
			||||||
      <template #picUrl="{ row }">
 | 
					      <template #picUrl="{ row }">
 | 
				
			||||||
        <el-image :src="row.picUrl" class="w-30px h-30px" @click="imagePreview(row.picUrl)" />
 | 
					        <el-image :src="row.picUrl" class="w-30px h-30px" @click="imagePreview(row.picUrl)" />
 | 
				
			||||||
      </template>
 | 
					      </template>
 | 
				
			||||||
 | 
					      <template #status="{ row }">
 | 
				
			||||||
 | 
					        <el-switch
 | 
				
			||||||
 | 
					          v-model="row.status"
 | 
				
			||||||
 | 
					          :active-value="0"
 | 
				
			||||||
 | 
					          :inactive-value="1"
 | 
				
			||||||
 | 
					          @change="handleStatusChange(row)"
 | 
				
			||||||
 | 
					        />
 | 
				
			||||||
 | 
					      </template>
 | 
				
			||||||
      <template #action="{ row }">
 | 
					      <template #action="{ row }">
 | 
				
			||||||
        <el-button
 | 
					        <el-button
 | 
				
			||||||
          v-hasPermi="['promotion:seckill-config:update']"
 | 
					          v-hasPermi="['promotion:seckill-config:update']"
 | 
				
			||||||
@@ -63,11 +65,13 @@
 | 
				
			|||||||
  <SeckillConfigForm ref="formRef" @success="getList" />
 | 
					  <SeckillConfigForm ref="formRef" @success="getList" />
 | 
				
			||||||
</template>
 | 
					</template>
 | 
				
			||||||
<script lang="ts" name="SeckillConfig" setup>
 | 
					<script lang="ts" name="SeckillConfig" setup>
 | 
				
			||||||
import { allSchemas, format } from './seckillConfig.data'
 | 
					import { allSchemas } from './seckillConfig.data'
 | 
				
			||||||
import * as SeckillConfigApi from '@/api/mall/promotion/seckill/seckillConfig'
 | 
					import * as SeckillConfigApi from '@/api/mall/promotion/seckill/seckillConfig'
 | 
				
			||||||
import SeckillConfigForm from './SeckillConfigForm.vue'
 | 
					import SeckillConfigForm from './SeckillConfigForm.vue'
 | 
				
			||||||
import { createImageViewer } from '@/components/ImageViewer'
 | 
					import { createImageViewer } from '@/components/ImageViewer'
 | 
				
			||||||
 | 
					import { CommonStatusEnum } from '@/utils/constants'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const message = useMessage() // 消息弹窗
 | 
				
			||||||
// tableObject:表格的属性对象,可获得分页大小、条数等属性
 | 
					// tableObject:表格的属性对象,可获得分页大小、条数等属性
 | 
				
			||||||
// tableMethods:表格的操作对象,可进行获得分页、删除记录等操作
 | 
					// tableMethods:表格的操作对象,可进行获得分页、删除记录等操作
 | 
				
			||||||
// 详细可见:https://doc.iocoder.cn/vue3/crud-schema/
 | 
					// 详细可见:https://doc.iocoder.cn/vue3/crud-schema/
 | 
				
			||||||
@@ -93,7 +97,22 @@ const openForm = (type: string, id?: number) => {
 | 
				
			|||||||
const handleDelete = (id: number) => {
 | 
					const handleDelete = (id: number) => {
 | 
				
			||||||
  tableMethods.delList(id, false)
 | 
					  tableMethods.delList(id, false)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					/** 修改用户状态 */
 | 
				
			||||||
 | 
					const handleStatusChange = async (row: SeckillConfigApi.SeckillConfigVO) => {
 | 
				
			||||||
 | 
					  try {
 | 
				
			||||||
 | 
					    // 修改状态的二次确认
 | 
				
			||||||
 | 
					    const text = row.status === CommonStatusEnum.ENABLE ? '启用' : '停用'
 | 
				
			||||||
 | 
					    await message.confirm('确认要"' + text + '""' + row.name + '?')
 | 
				
			||||||
 | 
					    // 发起修改状态
 | 
				
			||||||
 | 
					    await SeckillConfigApi.updateSeckillConfigStatus(row.id, row.status)
 | 
				
			||||||
 | 
					    // 刷新列表
 | 
				
			||||||
 | 
					    await getList()
 | 
				
			||||||
 | 
					  } catch {
 | 
				
			||||||
 | 
					    // 取消后,进行恢复按钮
 | 
				
			||||||
 | 
					    row.status =
 | 
				
			||||||
 | 
					      row.status === CommonStatusEnum.ENABLE ? CommonStatusEnum.DISABLE : CommonStatusEnum.ENABLE
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
/** 初始化 **/
 | 
					/** 初始化 **/
 | 
				
			||||||
onMounted(() => {
 | 
					onMounted(() => {
 | 
				
			||||||
  getList()
 | 
					  getList()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,6 @@ export const rules = reactive({
 | 
				
			|||||||
  name: [required],
 | 
					  name: [required],
 | 
				
			||||||
  startTime: [required],
 | 
					  startTime: [required],
 | 
				
			||||||
  endTime: [required],
 | 
					  endTime: [required],
 | 
				
			||||||
  seckillActivityCount: [required],
 | 
					 | 
				
			||||||
  picUrl: [required],
 | 
					  picUrl: [required],
 | 
				
			||||||
  status: [required]
 | 
					  status: [required]
 | 
				
			||||||
})
 | 
					})
 | 
				
			||||||
@@ -78,16 +77,3 @@ const crudSchemas = reactive<CrudSchema[]>([
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
])
 | 
					])
 | 
				
			||||||
export const { allSchemas } = useCrudSchemas(crudSchemas)
 | 
					export const { allSchemas } = useCrudSchemas(crudSchemas)
 | 
				
			||||||
 | 
					 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 *  添加这个函数呢是因为数据库表使用 time 类型存的时分秒信息,对应实体类字段使用的 LocalTime,然后返回给前端的就数据是
 | 
					 | 
				
			||||||
 *  '00:05:00' 会变成 [0,5],所以才使用此方法转一道。我想着或许直接后台返回字符串格式的
 | 
					 | 
				
			||||||
 * @param data
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
export const format = (data: number[]): string => {
 | 
					 | 
				
			||||||
  if (typeof data === 'undefined') {
 | 
					 | 
				
			||||||
    return ''
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  const paddedData = data.length >= 3 ? data.slice(0, 3) : [...data, 0, 0].slice(0, 3)
 | 
					 | 
				
			||||||
  return paddedData.map((num) => num.toString().padStart(2, '0')).join(':')
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user