generated from Leo_Ding/web-template
公司动态增删改查
This commit is contained in:
parent
8c933ddbf3
commit
f77d1391fa
@ -3,7 +3,6 @@ const modules = import.meta.glob('./modules/*.js', { eager: true })
|
|||||||
const api = {}
|
const api = {}
|
||||||
Object.keys(modules).forEach((key) => {
|
Object.keys(modules).forEach((key) => {
|
||||||
const name = key.slice(key.lastIndexOf('/') + 1, key.lastIndexOf('.'))
|
const name = key.slice(key.lastIndexOf('/') + 1, key.lastIndexOf('.'))
|
||||||
console.log(name)
|
|
||||||
api[name] = { ...modules[key] }
|
api[name] = { ...modules[key] }
|
||||||
})
|
})
|
||||||
export default api
|
export default api
|
||||||
|
|||||||
@ -5,3 +5,10 @@ export const getRegion = (params) => request.basic.get('/region', params)
|
|||||||
|
|
||||||
// 获取 验证码ID
|
// 获取 验证码ID
|
||||||
export const getCaptcha = (params) => request.basic.get('/api/v1/captcha/id', params)
|
export const getCaptcha = (params) => request.basic.get('/api/v1/captcha/id', params)
|
||||||
|
|
||||||
|
//上传图片
|
||||||
|
export const uploadFile=(params)=>request.basic.post('/api/v1/upload',params,{
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'multipart/form-data'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|||||||
14
src/apis/modules/dynamic.js
Normal file
14
src/apis/modules/dynamic.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* 海邻动态接口
|
||||||
|
*/
|
||||||
|
import request from '@/utils/request'
|
||||||
|
// 获取公司动态列表
|
||||||
|
export const getDataList = (params) => request.basic.get('/api/v1/articles', params)
|
||||||
|
// 获取单条数据
|
||||||
|
export const getItem = (id) => request.basic.get(`/api/v1/articles/${id}`)
|
||||||
|
// 添加动态
|
||||||
|
export const createDynamic = (params) => request.basic.post('/api/v1/articles', params)
|
||||||
|
// 更新动态
|
||||||
|
export const updateItem = (id, params) => request.basic.put(`/api/v1/articles/${id}`, params)
|
||||||
|
// 删除动态
|
||||||
|
export const delItem = (id) => request.basic.delete(`/api/v1/articles/${id}`)
|
||||||
@ -1,37 +1,23 @@
|
|||||||
<template>
|
<template>
|
||||||
<div
|
<div ref="uploadImageRef" class="x-upload x-upload-image" :class="{
|
||||||
ref="uploadImageRef"
|
'x-upload--round': round,
|
||||||
class="x-upload x-upload-image"
|
'x-upload--disabled': disabled,
|
||||||
:class="{
|
}">
|
||||||
'x-upload--round': round,
|
<a-upload v-if="showUploadBtn" :show-upload-list="false" :multiple="multiple" :before-upload="onBeforeUpload"
|
||||||
'x-upload--disabled': disabled,
|
:custom-request="({ file }) => customRequest(file)" :accept="accept" :disabled="disabled">
|
||||||
}">
|
|
||||||
<a-upload
|
|
||||||
v-if="showUploadBtn"
|
|
||||||
:show-upload-list="false"
|
|
||||||
:multiple="multiple"
|
|
||||||
:before-upload="onBeforeUpload"
|
|
||||||
:custom-request="({ file }) => customRequest(file)"
|
|
||||||
:accept="accept"
|
|
||||||
:disabled="disabled">
|
|
||||||
<slot>
|
<slot>
|
||||||
<div
|
<div class="x-upload-btn" :class="{
|
||||||
class="x-upload-btn"
|
'x-upload-btn--hover': !disabled,
|
||||||
:class="{
|
}" :style="{
|
||||||
'x-upload-btn--hover': !disabled,
|
width: `${width}px`,
|
||||||
}"
|
height: `${height}px`,
|
||||||
:style="{
|
}">
|
||||||
width: `${width}px`,
|
|
||||||
height: `${height}px`,
|
|
||||||
}">
|
|
||||||
<div class="x-upload-btn__icon">
|
<div class="x-upload-btn__icon">
|
||||||
<slot name="icon">
|
<slot name="icon">
|
||||||
<plus-outlined></plus-outlined>
|
<plus-outlined></plus-outlined>
|
||||||
</slot>
|
</slot>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div v-if="text" class="x-upload-btn__txt">
|
||||||
v-if="text"
|
|
||||||
class="x-upload-btn__txt">
|
|
||||||
<slot name="text">
|
<slot name="text">
|
||||||
{{ text }}
|
{{ text }}
|
||||||
</slot>
|
</slot>
|
||||||
@ -39,32 +25,20 @@
|
|||||||
</div>
|
</div>
|
||||||
</slot>
|
</slot>
|
||||||
</a-upload>
|
</a-upload>
|
||||||
<div
|
<div v-for="(item, index) in fileList" class="x-upload-item j-upload-item" :key="item.key" :class="{
|
||||||
v-for="(item, index) in fileList"
|
'x-upload-item--error': STATUS_ENUM.is('error', item.status),
|
||||||
class="x-upload-item j-upload-item"
|
}" :style="{
|
||||||
:key="item.key"
|
width: `${width}px`,
|
||||||
:class="{
|
height: `${height}px`,
|
||||||
'x-upload-item--error': STATUS_ENUM.is('error', item.status),
|
}">
|
||||||
}"
|
<img :src="item.src" alt="" />
|
||||||
:style="{
|
|
||||||
width: `${width}px`,
|
|
||||||
height: `${height}px`,
|
|
||||||
}">
|
|
||||||
<img
|
|
||||||
:src="item.src"
|
|
||||||
alt="" />
|
|
||||||
<template v-if="['error', 'done'].includes(STATUS_ENUM.getKey(item.status))">
|
<template v-if="['error', 'done'].includes(STATUS_ENUM.getKey(item.status))">
|
||||||
<div class="x-upload-actions">
|
<div class="x-upload-actions">
|
||||||
<div
|
<div v-if="STATUS_ENUM.is('done', item.status)" class="x-upload-action"
|
||||||
v-if="STATUS_ENUM.is('done', item.status)"
|
|
||||||
class="x-upload-action"
|
|
||||||
@click="handlePreview(item, index)">
|
@click="handlePreview(item, index)">
|
||||||
<eye-outlined />
|
<eye-outlined />
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div v-if="!disabled" class="x-upload-action" @click="handleRemove(index)">
|
||||||
v-if="!disabled"
|
|
||||||
class="x-upload-action"
|
|
||||||
@click="handleRemove(index)">
|
|
||||||
<delete-outlined />
|
<delete-outlined />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -73,16 +47,11 @@
|
|||||||
<div class="x-upload-status">
|
<div class="x-upload-status">
|
||||||
<template v-if="STATUS_ENUM.is('uploading', item.status)">
|
<template v-if="STATUS_ENUM.is('uploading', item.status)">
|
||||||
<div>{{ item.percent }}%</div>
|
<div>{{ item.percent }}%</div>
|
||||||
<a-progress
|
<a-progress :show-info="false" :stroke-width="4" :percent="item.percent" />
|
||||||
:show-info="false"
|
|
||||||
:stroke-width="4"
|
|
||||||
:percent="item.percent" />
|
|
||||||
</template>
|
</template>
|
||||||
<template v-if="STATUS_ENUM.is('wait', item.status)">
|
<template v-if="STATUS_ENUM.is('wait', item.status)">
|
||||||
<div>{{ STATUS_ENUM.getDesc(item.status) }}</div>
|
<div>{{ STATUS_ENUM.getDesc(item.status) }}</div>
|
||||||
<span
|
<span class="x-upload-action" @click="handleCancel(item)">
|
||||||
class="x-upload-action"
|
|
||||||
@click="handleCancel(item)">
|
|
||||||
取消上传
|
取消上传
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
@ -92,11 +61,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!--裁剪-->
|
<!--裁剪-->
|
||||||
<cropper-dialog
|
<cropper-dialog v-if="cropper && !multiple" ref="cropperDialogRef" :aspect-ratio="aspectRatio" :quality="quality"
|
||||||
v-if="cropper && !multiple"
|
|
||||||
ref="cropperDialogRef"
|
|
||||||
:aspect-ratio="aspectRatio"
|
|
||||||
:quality="quality"
|
|
||||||
@ok="(file) => customRequest(file)" />
|
@ok="(file) => customRequest(file)" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -113,7 +78,9 @@ import { deepMerge } from '@/utils/util'
|
|||||||
import CropperDialog from '../Cropper/CropperDialog.vue'
|
import CropperDialog from '../Cropper/CropperDialog.vue'
|
||||||
import Preview from '../Preview'
|
import Preview from '../Preview'
|
||||||
import { STATUS_ENUM } from './config'
|
import { STATUS_ENUM } from './config'
|
||||||
|
import apis from '@/apis'
|
||||||
|
import axios from 'axios'
|
||||||
|
import { config } from '@/config'
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'XUploadImage',
|
name: 'XUploadImage',
|
||||||
})
|
})
|
||||||
@ -188,7 +155,7 @@ const props = defineProps({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['update:modelValue'])
|
const emit = defineEmits(['update:modelValue','imgChange'])
|
||||||
|
|
||||||
useSlots(['icon', 'text'])
|
useSlots(['icon', 'text'])
|
||||||
|
|
||||||
@ -369,27 +336,30 @@ async function doUpload() {
|
|||||||
record.status = STATUS_ENUM.getValue('uploading')
|
record.status = STATUS_ENUM.getValue('uploading')
|
||||||
|
|
||||||
// 模拟示例
|
// 模拟示例
|
||||||
record.percent = 100
|
// record.percent = 100
|
||||||
record.status = STATUS_ENUM.getValue('done')
|
// record.status = STATUS_ENUM.getValue('done')
|
||||||
trigger()
|
// trigger()
|
||||||
await doUpload()
|
// await doUpload()
|
||||||
|
|
||||||
// 接口示例
|
// 接口示例
|
||||||
// const { code } = await apis.common.upload({
|
const formData = new FormData();
|
||||||
// file: record?.file,
|
// 添加文件
|
||||||
// })
|
formData.append('file', record.file);
|
||||||
// if (config('http.code.success') === code) {
|
const { success,data } = await apis.common.uploadFile(formData)
|
||||||
// // 上传进度
|
if (config('http.code.success') === success) {
|
||||||
// record.percent = 100
|
// 上传进度
|
||||||
// // 上传状态,根据实际情况更新
|
record.percent = 100
|
||||||
// record.status = STATUS_ENUM.getValue('done')
|
// 上传状态,根据实际情况更新
|
||||||
// // 更新文件 url
|
record.status = STATUS_ENUM.getValue('done')
|
||||||
// record.src = data?.src
|
// 更新文件 url
|
||||||
// // 触发事件
|
// record.src = success?.data
|
||||||
// trigger()
|
// 触发事件
|
||||||
// // 递归上传,检查是否还有未上传的文件
|
emit('imgChange', data)
|
||||||
// await doUpload()
|
// 递归上传,检查是否还有未上传的文件
|
||||||
// }
|
await doUpload()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -421,6 +391,7 @@ function trigger() {
|
|||||||
// 单选
|
// 单选
|
||||||
value = (fileList.value.length ? fileList.value[0]?.src : fileList.value[0]) ?? ''
|
value = (fileList.value.length ? fileList.value[0]?.src : fileList.value[0]) ?? ''
|
||||||
}
|
}
|
||||||
|
console.log(value)
|
||||||
emit('update:modelValue', value)
|
emit('update:modelValue', value)
|
||||||
onFieldChange()
|
onFieldChange()
|
||||||
}
|
}
|
||||||
@ -434,6 +405,7 @@ function trigger() {
|
|||||||
|
|
||||||
// 圆角
|
// 圆角
|
||||||
&--round {
|
&--round {
|
||||||
|
|
||||||
.x-upload-btn,
|
.x-upload-btn,
|
||||||
.x-upload-item {
|
.x-upload-item {
|
||||||
border-radius: 10em;
|
border-radius: 10em;
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { active } from "sortablejs";
|
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import list from './list'
|
|||||||
import profile from './profile'
|
import profile from './profile'
|
||||||
import result from './result'
|
import result from './result'
|
||||||
import exception from './exception'
|
import exception from './exception'
|
||||||
// import admin from './admin'
|
import admin from './admin'
|
||||||
import system from './system'
|
import system from './system'
|
||||||
import link from './link'
|
import link from './link'
|
||||||
import iframe from './iframe'
|
import iframe from './iframe'
|
||||||
@ -19,7 +19,7 @@ export default [
|
|||||||
...profile,
|
...profile,
|
||||||
...result,
|
...result,
|
||||||
...exception,
|
...exception,
|
||||||
// ...admin,
|
...admin,
|
||||||
...system,
|
...system,
|
||||||
...link,
|
...link,
|
||||||
...iframe,
|
...iframe,
|
||||||
|
|||||||
@ -87,7 +87,6 @@ const basic = new XYHttp({
|
|||||||
...options,
|
...options,
|
||||||
baseURL: config('http.apiBasic'),
|
baseURL: config('http.apiBasic'),
|
||||||
})
|
})
|
||||||
console.log(basic)
|
|
||||||
const readFile = new ReadFile()
|
const readFile = new ReadFile()
|
||||||
export default {
|
export default {
|
||||||
basic,
|
basic,
|
||||||
|
|||||||
@ -1,112 +1,35 @@
|
|||||||
<template>
|
<template>
|
||||||
<a-modal
|
<a-modal :open="modal.open" :title="modal.title" :width="640" :confirm-loading="modal.confirmLoading"
|
||||||
:open="modal.open"
|
:after-close="onAfterClose" :cancel-text="cancelText" :ok-text="okText" @ok="handleOk" @cancel="handleCancel">
|
||||||
:title="modal.title"
|
<a-form ref="formRef" :model="formData" :rules="formRules">
|
||||||
:width="640"
|
|
||||||
:confirm-loading="modal.confirmLoading"
|
|
||||||
:after-close="onAfterClose"
|
|
||||||
:cancel-text="cancelText"
|
|
||||||
:ok-text="okText"
|
|
||||||
@ok="handleOk"
|
|
||||||
@cancel="handleCancel">
|
|
||||||
<a-form
|
|
||||||
ref="formRef"
|
|
||||||
:model="formData"
|
|
||||||
:rules="formRules"
|
|
||||||
:label-col="{ style: { width: '90px' } }">
|
|
||||||
<a-card class="mb-8-2">
|
<a-card class="mb-8-2">
|
||||||
<a-row :gutter="12">
|
|
||||||
<a-col :span="12">
|
|
||||||
<a-form-item
|
|
||||||
:label="$t('pages.system.user.form.username')"
|
|
||||||
name="username">
|
|
||||||
<a-input
|
|
||||||
:placeholder="$t('pages.system.user.form.username.placeholder')"
|
|
||||||
v-model:value="formData.username"></a-input>
|
|
||||||
</a-form-item>
|
|
||||||
</a-col>
|
|
||||||
<a-col :span="12">
|
|
||||||
<a-form-item
|
|
||||||
:label="$t('pages.system.user.form.password')"
|
|
||||||
name="password">
|
|
||||||
<a-input-password
|
|
||||||
v-model:value="formData.password"
|
|
||||||
:placeholder="$t('pages.system.user.form.password.placeholder')" />
|
|
||||||
</a-form-item>
|
|
||||||
</a-col>
|
|
||||||
</a-row>
|
|
||||||
<a-row :gutter="12">
|
|
||||||
<a-col :span="12">
|
|
||||||
<a-form-item
|
|
||||||
:label="$t('pages.system.user.form.name')"
|
|
||||||
name="name">
|
|
||||||
<a-input
|
|
||||||
:placeholder="$t('pages.system.user.form.name.placeholder')"
|
|
||||||
v-model:value="formData.name"></a-input>
|
|
||||||
</a-form-item>
|
|
||||||
</a-col>
|
|
||||||
<a-col :span="12">
|
|
||||||
<a-form-item
|
|
||||||
:label="$t('pages.system.user.form.roles')"
|
|
||||||
name="roles">
|
|
||||||
<a-select
|
|
||||||
v-model:value="formData.roles"
|
|
||||||
mode="multiple"
|
|
||||||
style="width: 100%"
|
|
||||||
:placeholder="$t('pages.system.user.form.roles.placeholder')"
|
|
||||||
:options="roles"
|
|
||||||
@change="handleChange"></a-select>
|
|
||||||
</a-form-item>
|
|
||||||
</a-col>
|
|
||||||
</a-row>
|
|
||||||
|
|
||||||
<a-row :gutter="12">
|
|
||||||
<a-col :span="12">
|
|
||||||
<a-form-item
|
|
||||||
:label="$t('pages.system.user.form.phone')"
|
|
||||||
type="tel"
|
|
||||||
name="phone">
|
|
||||||
<a-input
|
|
||||||
:placeholder="$t('pages.system.user.form.phone.placeholder')"
|
|
||||||
type="tel"
|
|
||||||
v-model:value="formData.phone"></a-input>
|
|
||||||
</a-form-item>
|
|
||||||
</a-col>
|
|
||||||
<a-col :span="12">
|
|
||||||
<a-form-item
|
|
||||||
:label="$t('pages.system.user.form.email')"
|
|
||||||
type="email"
|
|
||||||
name="email">
|
|
||||||
<a-input
|
|
||||||
:placeholder="$t('pages.system.user.form.email.placeholder')"
|
|
||||||
type="email"
|
|
||||||
v-model:value="formData.email"></a-input>
|
|
||||||
</a-form-item>
|
|
||||||
</a-col>
|
|
||||||
</a-row>
|
|
||||||
|
|
||||||
<a-row :gutter="12">
|
<a-row :gutter="12">
|
||||||
<a-col :span="24">
|
<a-col :span="24">
|
||||||
<a-form-item
|
<a-form-item :label="'标题'" name="title">
|
||||||
:label="$t('pages.system.user.form.remark')"
|
<a-input :placeholder="'请输入标题'" v-model:value="formData.title"></a-input>
|
||||||
name="remark">
|
|
||||||
<a-textarea
|
|
||||||
:placeholder="$t('pages.system.user.form.remark.placeholder')"
|
|
||||||
v-model:value="formData.remark"></a-textarea>
|
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
|
||||||
<a-row :gutter="12">
|
|
||||||
<a-col :span="24">
|
<a-col :span="24">
|
||||||
<a-form-item
|
<a-form-item :label="'内容'" name="content">
|
||||||
:label="$t('pages.system.user.form.status')"
|
<a-textarea :placeholder="'内容'" v-model:value="formData.content"></a-textarea>
|
||||||
name="status">
|
</a-form-item>
|
||||||
<a-radio-group
|
</a-col>
|
||||||
v-model:value="formData.status"
|
<a-col :span="24">
|
||||||
:options="[
|
<a-form-item :label="'链接'" name="link">
|
||||||
{ label: $t('pages.system.user.form.status.activated'), value: 'activated' },
|
<a-input v-model:value="formData.link" :placeholder="'请输入链接'" />
|
||||||
{ label: $t('pages.system.user.form.status.freezed'), value: 'freezed' },
|
</a-form-item>
|
||||||
]"></a-radio-group>
|
</a-col>
|
||||||
|
<a-col :span="24">
|
||||||
|
<a-form-item :label="'状态'" name="status">
|
||||||
|
<a-radio-group v-model:value="formData.status" :options="[
|
||||||
|
{ label: '启用', value: 'enabled' },
|
||||||
|
{ label: '停用', value: 'disabled' },
|
||||||
|
]"></a-radio-group>
|
||||||
|
</a-form-item>
|
||||||
|
</a-col>
|
||||||
|
<a-col :span="24">
|
||||||
|
<a-form-item :label="'图片'" name="imgUrl">
|
||||||
|
<x-upload-image v-model="imgUrl" @imgChange="imgChange"/>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
@ -123,6 +46,7 @@ import apis from '@/apis'
|
|||||||
import { useForm, useModal } from '@/hooks'
|
import { useForm, useModal } from '@/hooks'
|
||||||
import { message } from 'ant-design-vue'
|
import { message } from 'ant-design-vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
const emit = defineEmits(['ok'])
|
const emit = defineEmits(['ok'])
|
||||||
const { t } = useI18n() // 解构出t方法
|
const { t } = useI18n() // 解构出t方法
|
||||||
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
|
const { modal, showModal, hideModal, showLoading, hideLoading } = useModal()
|
||||||
@ -131,18 +55,16 @@ const cancelText = ref(t('button.cancel'))
|
|||||||
const okText = ref(t('button.confirm'))
|
const okText = ref(t('button.confirm'))
|
||||||
const rolesValue = ref([])
|
const rolesValue = ref([])
|
||||||
const roles = ref([])
|
const roles = ref([])
|
||||||
|
const imgUrl=ref('')
|
||||||
formRules.value = {
|
formRules.value = {
|
||||||
name: { required: true, message: t('pages.system.user.form.username.placeholder') },
|
title: { required: true, message: '请输入标题' },
|
||||||
username: { required: true, message: t('pages.system.user.form.code.placeholder') },
|
content: { required: true, message: '请输入内容' },
|
||||||
status: { required: true, message: t('pages.system.user.form.status') },
|
link: { required: true, message: '请输入链接' },
|
||||||
roles: [{ required: true, message: t('pages.system.user.form.roles.placeholder'), trigger: 'change' }],
|
status: [{ required: true, message: '请选择状态', trigger: 'change' }],
|
||||||
|
// imgUrl: [{ required: true, message: '请上传图片', trigger: 'change' }],
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 请求角色
|
|
||||||
*/
|
|
||||||
getRole()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* select 选择框
|
* select 选择框
|
||||||
@ -150,34 +72,21 @@ getRole()
|
|||||||
const handleChange = (value) => {
|
const handleChange = (value) => {
|
||||||
rolesValue.value = value
|
rolesValue.value = value
|
||||||
}
|
}
|
||||||
|
const imgChange=(value)=>{
|
||||||
|
formData.value.img=value
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 新建
|
* 新建
|
||||||
*/
|
*/
|
||||||
function handleCreate() {
|
function handleCreate() {
|
||||||
showModal({
|
showModal({
|
||||||
type: 'create',
|
type: 'create',
|
||||||
title: t('pages.system.user.add'),
|
title: '添加公司动态',
|
||||||
})
|
})
|
||||||
|
formData.value.status = 'enabled'
|
||||||
}
|
}
|
||||||
async function getRole() {
|
|
||||||
const { success, data } = await apis.role.getRoleList().catch(() => {
|
|
||||||
throw new Error()
|
|
||||||
})
|
|
||||||
if (!success) {
|
|
||||||
return message.error('当前角色信息错误')
|
|
||||||
}
|
|
||||||
let roleArr = []
|
|
||||||
if (data.length) {
|
|
||||||
data.forEach((item) => {
|
|
||||||
roleArr.push({
|
|
||||||
label: item.name,
|
|
||||||
value: item.id,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
roles.value = roleArr
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* 编辑
|
* 编辑
|
||||||
*/
|
*/
|
||||||
@ -186,44 +95,40 @@ async function handleEdit(record = {}) {
|
|||||||
type: 'edit',
|
type: 'edit',
|
||||||
title: t('pages.system.user.edit'),
|
title: t('pages.system.user.edit'),
|
||||||
})
|
})
|
||||||
const { data, success } = await apis.users.getUsers(record.id).catch()
|
const { data, success } = await apis.dynamic.getItem(record.id).catch()
|
||||||
if (!success) {
|
if (!success) {
|
||||||
hideModal()
|
hideModal()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let roles = []
|
formData.value = {...data}
|
||||||
if (data.roles) {
|
imgUrl.value=config('http.apiBasic')+data.img
|
||||||
roles = formatArr(data.roles, 'edit')
|
|
||||||
}
|
|
||||||
|
|
||||||
data.roles = roles
|
|
||||||
formRecord.value = data
|
|
||||||
formData.value = cloneDeep(data)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 确定
|
* 确定
|
||||||
*/
|
*/
|
||||||
function handleOk() {
|
function handleOk() {
|
||||||
formRef.value
|
if(!formData.value.img) return message.error('请上传图片');
|
||||||
.validateFields()
|
formRef.value.validateFields().then(async (values) => {
|
||||||
.then(async (values) => {
|
console.log(values)
|
||||||
try {
|
try {
|
||||||
showLoading()
|
showLoading()
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
...values,
|
...values,
|
||||||
roles: formatArr(rolesValue.value),
|
img:formData.value.img,
|
||||||
|
pushAt:dayjs().format('YYYY-MM-DD'),
|
||||||
|
type:'news'
|
||||||
}
|
}
|
||||||
let result = null
|
let result = null
|
||||||
|
console.log(modal.value.type)
|
||||||
switch (modal.value.type) {
|
switch (modal.value.type) {
|
||||||
case 'create':
|
case 'create':
|
||||||
result = await apis.users.createUsers(params).catch(() => {
|
result = await apis.dynamic.createDynamic(params).catch(() => {
|
||||||
throw new Error()
|
throw new Error()
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case 'edit':
|
case 'edit':
|
||||||
result = await apis.users.updateUsers(formData.value.id, params).catch(() => {
|
result = await apis.dynamic.updateItem(formData.value.id, params).catch(() => {
|
||||||
throw new Error()
|
throw new Error()
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
@ -234,10 +139,12 @@ function handleOk() {
|
|||||||
emit('ok')
|
emit('ok')
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log(error)
|
||||||
hideLoading()
|
hideLoading()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch((e) => {
|
||||||
|
console.log(e)
|
||||||
hideLoading()
|
hideLoading()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -273,6 +180,7 @@ function formatArr(data, type = '') {
|
|||||||
* 取消
|
* 取消
|
||||||
*/
|
*/
|
||||||
function handleCancel() {
|
function handleCancel() {
|
||||||
|
imgUrl.value=''
|
||||||
hideModal()
|
hideModal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,44 +1,28 @@
|
|||||||
<template>
|
<template>
|
||||||
<x-search-bar class="mb-8-2">
|
<x-search-bar class="mb-8-2">
|
||||||
<template #default="{ gutter, colSpan }">
|
<template #default="{ gutter, colSpan }">
|
||||||
<a-form
|
<a-form :label-col="{ style: { width: '40px' } }" :model="searchFormData" layout="inline">
|
||||||
:label-col="{ style: { width: '100px' } }"
|
|
||||||
:model="searchFormData"
|
|
||||||
layout="inline">
|
|
||||||
<a-row :gutter="gutter">
|
<a-row :gutter="gutter">
|
||||||
<a-col v-bind="colSpan">
|
<a-col v-bind="colSpan">
|
||||||
<a-form-item
|
<a-form-item label="标题" name="title">
|
||||||
:label="$t('pages.system.user.form.username')"
|
<a-input placeholder="请输入公司动态标题" v-model:value="searchFormData.title"></a-input>
|
||||||
name="username">
|
|
||||||
<a-input
|
|
||||||
:placeholder="$t('pages.system.user.form.username.placeholder')"
|
|
||||||
v-model:value="searchFormData.username"></a-input>
|
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-col>
|
</a-col>
|
||||||
|
|
||||||
<a-col v-bind="colSpan">
|
<a-col v-bind="colSpan">
|
||||||
<a-form-item name="name">
|
<a-form-item label="状态" name="status">
|
||||||
<template #label>
|
<a-select v-model:value="searchFormData.status" allowClear>
|
||||||
{{ $t('pages.system.user.form.name') }}
|
<a-select-option value="">全部</a-select-option>
|
||||||
<a-tooltip :title="$t('pages.system.user.form.name')">
|
<a-select-option value="enabled">启用</a-select-option>
|
||||||
<question-circle-outlined class="ml-4-1 color-placeholder" />
|
<a-select-option value="disabled">停用</a-select-option>
|
||||||
</a-tooltip>
|
</a-select>
|
||||||
</template>
|
|
||||||
<a-input
|
|
||||||
:placeholder="$t('pages.system.user.form.name.placeholder')"
|
|
||||||
v-model:value="searchFormData.name"></a-input>
|
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-col>
|
</a-col>
|
||||||
|
|
||||||
<a-col
|
<a-col class="align-right" v-bind="colSpan">
|
||||||
class="align-right"
|
|
||||||
v-bind="colSpan">
|
|
||||||
<a-space>
|
<a-space>
|
||||||
<a-button @click="handleResetSearch">{{ $t('button.reset') }}</a-button>
|
<a-button @click="handleResetSearch">{{ $t('button.reset') }}</a-button>
|
||||||
<a-button
|
<a-button ghost type="primary" @click="handleSearch">
|
||||||
ghost
|
|
||||||
type="primary"
|
|
||||||
@click="handleSearch">
|
|
||||||
{{ $t('button.search') }}
|
{{ $t('button.search') }}
|
||||||
</a-button>
|
</a-button>
|
||||||
</a-space>
|
</a-space>
|
||||||
@ -47,58 +31,52 @@
|
|||||||
</a-form>
|
</a-form>
|
||||||
</template>
|
</template>
|
||||||
</x-search-bar>
|
</x-search-bar>
|
||||||
<a-row
|
<a-row :gutter="8" :wrap="false">
|
||||||
:gutter="8"
|
|
||||||
:wrap="false">
|
|
||||||
<a-col flex="auto">
|
<a-col flex="auto">
|
||||||
<a-card type="flex">
|
<a-card type="flex">
|
||||||
<x-action-bar class="mb-8-2">
|
<x-action-bar class="mb-8-2">
|
||||||
<a-button
|
<a-button type="primary" @click="$refs.editDialogRef.handleCreate()">
|
||||||
type="primary"
|
|
||||||
@click="$refs.editDialogRef.handleCreate()">
|
|
||||||
<template #icon>
|
<template #icon>
|
||||||
<plus-outlined></plus-outlined>
|
<plus-outlined></plus-outlined>
|
||||||
</template>
|
</template>
|
||||||
{{ $t('pages.system.user.add') }}
|
添加动态
|
||||||
</a-button>
|
</a-button>
|
||||||
</x-action-bar>
|
</x-action-bar>
|
||||||
<a-table
|
<a-table :columns="columns" :data-source="listData" bordered="true" :loading="loading"
|
||||||
:columns="columns"
|
:pagination="paginationState" :scroll="{ x: 1000 }" @change="onTableChange">
|
||||||
:data-source="listData"
|
|
||||||
:loading="loading"
|
|
||||||
:pagination="paginationState"
|
|
||||||
:scroll="{ x: 1000 }"
|
|
||||||
@change="onTableChange">
|
|
||||||
<template #bodyCell="{ column, record }">
|
<template #bodyCell="{ column, record }">
|
||||||
<template v-if="'statusType' === column.key">
|
<template v-if="'img' === column.dataIndex">
|
||||||
<!--状态-->
|
<a-image :width="60" :src="config('http.apiBasic') + record.img || $imageErr.imgErr" />
|
||||||
<a-tag
|
|
||||||
v-if="statusUserTypeEnum.is('activated', record.status)"
|
|
||||||
color="processing">
|
|
||||||
{{ statusUserTypeEnum.getDesc(record.status) }}
|
|
||||||
</a-tag>
|
|
||||||
<!--状态-->
|
|
||||||
<a-tag
|
|
||||||
v-if="statusUserTypeEnum.is('freezed', record.status)"
|
|
||||||
color="processing">
|
|
||||||
{{ statusUserTypeEnum.getDesc(record.status) }}
|
|
||||||
</a-tag>
|
|
||||||
</template>
|
</template>
|
||||||
|
<template v-if="column.dataIndex === 'title'">
|
||||||
<template v-if="'createAt' === column.key">
|
<a-tooltip :title="record.title">
|
||||||
{{ formatUtcDateTime(record.created_at) }}
|
<span>{{ record.title }}</span>
|
||||||
|
</a-tooltip>
|
||||||
|
</template>
|
||||||
|
<template v-if="column.dataIndex === 'content'">
|
||||||
|
<a-tooltip :title="record.content">
|
||||||
|
<span>{{ record.content }}</span>
|
||||||
|
</a-tooltip>
|
||||||
|
</template>
|
||||||
|
<template v-if="column.dataIndex === 'link'">
|
||||||
|
<a-tooltip :title="record.link">
|
||||||
|
<a :href="record.link" target="_blank" style="text-decoration: underline;">{{
|
||||||
|
record.link }}</a>
|
||||||
|
</a-tooltip>
|
||||||
|
</template>
|
||||||
|
<template v-if="'status' === column.dataIndex">
|
||||||
|
<a-tag v-if="record.status === 'enabled'" :color="'green'">启用</a-tag>
|
||||||
|
<a-tag v-if="record.status === 'disabled'" :color="'red'">停用</a-tag>
|
||||||
</template>
|
</template>
|
||||||
<template v-if="'action' === column.key">
|
<template v-if="'action' === column.key">
|
||||||
<x-action-button @click="$refs.editDialogRef.handleEdit(record)">
|
<x-action-button @click="$refs.editDialogRef.handleEdit(record)">
|
||||||
<a-tooltip>
|
<a-tooltip>
|
||||||
<template #title> {{ $t('pages.system.user.edit') }}</template>
|
<template #title> {{ $t('pages.system.user.edit') }}</template>
|
||||||
<edit-outlined /> </a-tooltip
|
<edit-outlined /> </a-tooltip></x-action-button>
|
||||||
></x-action-button>
|
|
||||||
<x-action-button @click="handleDelete(record)">
|
<x-action-button @click="handleDelete(record)">
|
||||||
<a-tooltip>
|
<a-tooltip>
|
||||||
<template #title>{{ $t('pages.system.delete') }}</template>
|
<template #title>{{ $t('pages.system.delete') }}</template>
|
||||||
<delete-outlined style="color: #ff4d4f" /> </a-tooltip
|
<delete-outlined style="color: #ff4d4f" /> </a-tooltip></x-action-button>
|
||||||
></x-action-button>
|
|
||||||
</template>
|
</template>
|
||||||
</template>
|
</template>
|
||||||
</a-table>
|
</a-table>
|
||||||
@ -106,9 +84,7 @@
|
|||||||
</a-col>
|
</a-col>
|
||||||
</a-row>
|
</a-row>
|
||||||
|
|
||||||
<edit-dialog
|
<edit-dialog ref="editDialogRef" @ok="onOk"></edit-dialog>
|
||||||
ref="editDialogRef"
|
|
||||||
@ok="onOk"></edit-dialog>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@ -124,17 +100,17 @@ import EditDialog from './components/EditDialog.vue'
|
|||||||
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
|
import { PlusOutlined, EditOutlined, DeleteOutlined } from '@ant-design/icons-vue'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'companyNews',
|
name: 'homeBanner',
|
||||||
})
|
})
|
||||||
const { t } = useI18n() // 解构出t方法
|
const { t } = useI18n() // 解构出t方法
|
||||||
const columns = [
|
const columns = [
|
||||||
{ title: t('pages.system.user.form.username'), dataIndex: 'username', width: 120 },
|
{ title: '图片', dataIndex: 'img', width: 100, align: 'center' },
|
||||||
{ title: t('pages.system.user.form.name'), dataIndex: 'name', key: 'name', width: 100 },
|
{ title: '标题', dataIndex: 'title', key: 'title' },
|
||||||
{ title: t('pages.system.user.form.phone'), dataIndex: 'phone', width: 120 },
|
{ title: '内容', dataIndex: 'content', key: 'content' },
|
||||||
{ title: t('pages.system.user.form.email'), dataIndex: 'email', width: 100 },
|
{ title: '状态', dataIndex: 'status', width: 120, align: 'center' },
|
||||||
{ title: t('pages.system.user.form.status'), dataIndex: 'status', key: 'statusType', width: 60 },
|
{ title: '发布日期', dataIndex: 'pushAt', width: 120, align: 'center' },
|
||||||
{ title: t('pages.system.user.form.created_at'), key: 'createAt', fixed: 'right', width: 120 },
|
{ title: '链接', dataIndex: 'link', align: 'center' },
|
||||||
{ title: t('button.action'), key: 'action', fixed: 'right', width: 100 },
|
{ title: t('button.action'), key: 'action', fixed: 'right', width: 100, align: 'center' },
|
||||||
]
|
]
|
||||||
|
|
||||||
const { listData, loading, showLoading, hideLoading, paginationState, resetPagination, searchFormData } =
|
const { listData, loading, showLoading, hideLoading, paginationState, resetPagination, searchFormData } =
|
||||||
@ -150,8 +126,8 @@ async function getPageList() {
|
|||||||
try {
|
try {
|
||||||
showLoading()
|
showLoading()
|
||||||
const { pageSize, current } = paginationState
|
const { pageSize, current } = paginationState
|
||||||
const { success, data, total } = await apis.users
|
const { success, data, total } = await apis.dynamic
|
||||||
.getUsersList({
|
.getDataList({
|
||||||
pageSize,
|
pageSize,
|
||||||
page: current,
|
page: current,
|
||||||
...searchFormData.value,
|
...searchFormData.value,
|
||||||
@ -179,9 +155,9 @@ function handleDelete({ id }) {
|
|||||||
okText: t('button.confirm'),
|
okText: t('button.confirm'),
|
||||||
onOk: () => {
|
onOk: () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
;(async () => {
|
; (async () => {
|
||||||
try {
|
try {
|
||||||
const { success } = await apis.users.delUsers(id).catch(() => {
|
const { success } = await apis.dynamic.delItem(id).catch(() => {
|
||||||
throw new Error()
|
throw new Error()
|
||||||
})
|
})
|
||||||
if (config('http.code.success') === success) {
|
if (config('http.code.success') === success) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user