diff --git a/cdTMP/package.json b/cdTMP/package.json index ba62d91..084fa09 100644 --- a/cdTMP/package.json +++ b/cdTMP/package.json @@ -1,7 +1,7 @@ { "name": "cdtmp", "private": true, - "version": "0.0.1", + "version": "0.0.2", "type": "module", "scripts": { "dev": "vite", diff --git a/cdTMP/src/api/request.js b/cdTMP/src/api/request.js index 66c2e70..95f6949 100644 --- a/cdTMP/src/api/request.js +++ b/cdTMP/src/api/request.js @@ -6,7 +6,7 @@ import qs, { stringify } from "qs" import { h } from "vue" import { IconFaceFrownFill } from "@arco-design/web-vue/dist/arco-vue-icon" -// createService +// 创建axios实例,添加请求和响应拦截器,返回该axios实例 function createService() { // 创建axios实例 const service = axios.create() @@ -21,7 +21,6 @@ function createService() { // 实例的response响应拦截器 service.interceptors.response.use( (res) => { - // 如果发现响应头有文件传输扩展,或者响应头为application/json,或者直接status=200 if ( (res.headers["content-disposition"] || !/^application\/json/.test(res.headers["content-type"])) && res.status === 200 @@ -33,17 +32,15 @@ function createService() { res.data.message = "服务器内部错误" res.data.success = false } else if (res.data.code && res.data.code !== 200) { + // 如果data里面code字段不为200 Message.error({ content: res.data.message, - // 注意奇怪的用法 icon: () => h(IconFaceFrownFill) }) } return res.data }, (error) => { - // 其实基本逻辑是有message写message - // 没用message再去找默认的response的status const err = (text) => { Message.error({ content: @@ -79,6 +76,7 @@ function createService() { break default: err("未知错误!") + break } } else { err("请求超时,服务器无响应!") @@ -96,7 +94,6 @@ function createService() { function createRequest(service) { return function (config) { const env = import.meta.env - // localStorage获取token信息 const token = tool.local.get(env.VITE_APP_TOKEN_PREFIX) const configDefault = { headers: { @@ -108,12 +105,7 @@ function createRequest(service) { baseURL: env.VITE_APP_OPEN_PROXY === "true" ? env.VITE_APP_PROXY_PREFIX : env.VITE_APP_BASE_URL, data: {} } - // option是configDefault和传入的config合并 const option = Object.assign(configDefault, config) - // lodash的isEmpty函数可以判断对象属性是否为空/数组是否为空->为空则返回true - // qs中stringfy作用是urlencode - // { c: 'b', a: 'd' } -> 'c=b&a=d' - // 如果有params就转为urlencode样子 if (!isEmpty(option.params)) { option.url = option.url + "?" + stringify(option.params) option.params = {} @@ -122,7 +114,5 @@ function createRequest(service) { } } -// 上面两个函数一个为增加实例拦截器,一个是传入实例后请求 export const service = createService() -// 返回的是一个函数,这个函数传入config然后添加上默认config然后发出实例的请求 export const request = createRequest(service) diff --git a/cdTMP/src/components/ma-crud/components/form.vue b/cdTMP/src/components/ma-crud/components/form.vue index aa40688..cf9cf74 100644 --- a/cdTMP/src/components/ma-crud/components/form.vue +++ b/cdTMP/src/components/ma-crud/components/form.vue @@ -1,8 +1,10 @@ diff --git a/cdTMP/src/views/datamanage/dictmanage/DataList/index.vue b/cdTMP/src/views/datamanage/dictmanage/DataList/index.vue new file mode 100644 index 0000000..5613ef3 --- /dev/null +++ b/cdTMP/src/views/datamanage/dictmanage/DataList/index.vue @@ -0,0 +1,43 @@ + + + + + diff --git a/cdTMP/src/views/datamanage/dictmanage/DataList/useCrudRef.ts b/cdTMP/src/views/datamanage/dictmanage/DataList/useCrudRef.ts new file mode 100644 index 0000000..b3a4809 --- /dev/null +++ b/cdTMP/src/views/datamanage/dictmanage/DataList/useCrudRef.ts @@ -0,0 +1,120 @@ +import { ref, type Ref } from "vue" +import dictApi from "@/api/system/dict" +/** + * 定义crud的ref以及其 + */ +export default function useCrudRef(currentRow: Ref<{ id: number | string; name: string }>) { + const crudRef = ref() + // crud选项 + const crudOptions = ref({ + autoRequest: false, + api: dictApi.getDictItemAll, + showIndex: false, + rowSelection: { showCheckedAll: true }, + operationColumn: true, + operationWidth: 160, + operationColumnAlign: "center", + showTools: false, + beforeAdd: (form: any) => { + form.id = currentRow.value?.id + }, + add: { show: true, api: dictApi.saveDictItem }, + edit: { show: true, api: dictApi.updateDictItemData }, + delete: { show: true, api: dictApi.realDeleteItem }, + afterDelete(response) { + crudRef.value.tableRef.selectAll(false) + } + }) + + // crudColumns + const columns = ref([ + { title: "ID", dataIndex: "id", addDisplay: false, editDisplay: false, width: 50, hide: true }, + { + title: "字典标签", + align: "center", + dataIndex: "title", + search: true, + width: 150, + commonRules: [{ required: true, message: "字典标签必填" }] + }, + { + title: "字段缩写", + dataIndex: "show_title", + align: "center", + search: true + }, + { + title: "字典键值", + align: "center", + dataIndex: "key", + addDisplay: false, + editDisplay: false, + search: true, + commonRules: [{ required: true, message: "字典键值必填" }] + }, + { + title: "排序", + align: "center", + dataIndex: "sort", + formType: "input-number", + addDefaultValue: 1, + width: 130, + min: 0, + max: 1000 + }, + { + title: "状态", + align: "center", + dataIndex: "status", + search: true, + addDefaultValue: "1", + formType: "radio", + dict: { name: "data_status", props: { label: "title", value: "key" } }, + width: 70 + }, + { + title: "备注", + align: "center", + dataIndex: "remark", + hide: true, + formType: "textarea" + }, + { + title: "更新时间", + align: "center", + dataIndex: "update_datetime", + addDisplay: false, + editDisplay: false, + search: true, + formType: "range", + width: 110 + }, + { + title: "文档名称", + dataIndex: "doc_name", + align: "center", + search: false, + placeholder: "如果不是标准则不填" + }, + { + title: "发布日期", + dataIndex: "publish_date", + align: "center", + search: false, + placeholder: "如果不是标准则不填" + }, + { + title: "标准来源", + dataIndex: "source", + align: "center", + search: false, + placeholder: "如果不是标准则不填" + } + ]) + + return { + crudRef, + crudOptions, + columns + } +} diff --git a/cdTMP/src/views/datamanage/dictmanage/DataList/useOpenChangeModal.ts b/cdTMP/src/views/datamanage/dictmanage/DataList/useOpenChangeModal.ts new file mode 100644 index 0000000..c67de64 --- /dev/null +++ b/cdTMP/src/views/datamanage/dictmanage/DataList/useOpenChangeModal.ts @@ -0,0 +1,63 @@ +import { ref, type Ref } from "vue" +import dictApi from "@/api/system/dict" +import { Message } from "@arco-design/web-vue" +import MaCrud from "@/components/ma-crud/index.vue" +/** + * 1.打开该modal方法/改变状态/改变排序 + */ +export default function useOpenChangeModal(crudRef: Ref>, currentRow: Ref) { + // refs + const visible = ref(false) + // 事件处理 + const changeSort = async (value: number, id: number): Promise => { + const response = await dictApi.numberOperation({ id, numberName: "sort", numberValue: value }) + response.success && Message.success(response.message) + crudRef.value.refresh() + } + const changeStatus = async (status: number | string, id: number): Promise => { + const response = await dictApi.changeItemStatus({ id, status }) + if (response.success) { + Message.success(response.message) + } + } + // 定义该open方法并暴露给组件外部 + // 打开a-modal事件 + const open = (row: Ref) => { + currentRow.value = row + // 调用固定方法请求数据 + crudRef.value.requestParams = { id: currentRow.value.id } + crudRef.value.requestData() + visible.value = true + // 判断如果是行数据的code值为standard则不显示‘文档名称’‘发布来源’‘发布日期’,且表单也不显示 + // columnService可以动态设置表格列的属性!!! + const columnService = crudRef.value.getColumnService() + if (currentRow.value.code === "standard") { + columnService.get("doc_name").setAttr("hide", false) + columnService.get("publish_date").setAttr("hide", false) + columnService.get("source").setAttr("hide", false) + columnService.get("doc_name").setAttr("addDisplay", true) + columnService.get("publish_date").setAttr("addDisplay", true) + columnService.get("source").setAttr("addDisplay", true) + columnService.get("doc_name").setAttr("editDisplay", true) + columnService.get("publish_date").setAttr("editDisplay", true) + columnService.get("source").setAttr("editDisplay", true) + } else { + columnService.get("doc_name").setAttr("hide", true) + columnService.get("publish_date").setAttr("hide", true) + columnService.get("source").setAttr("hide", true) + columnService.get("doc_name").setAttr("addDisplay", false) + columnService.get("publish_date").setAttr("addDisplay", false) + columnService.get("source").setAttr("addDisplay", false) + columnService.get("doc_name").setAttr("editDisplay", false) + columnService.get("publish_date").setAttr("editDisplay", false) + columnService.get("source").setAttr("editDisplay", false) + } + } + + return { + visible, + changeSort, + changeStatus, + open + } +} diff --git a/cdTMP/src/views/datamanage/dictmanage/dataList.vue b/cdTMP/src/views/datamanage/dictmanage/dataList.vue deleted file mode 100644 index 26f2370..0000000 --- a/cdTMP/src/views/datamanage/dictmanage/dataList.vue +++ /dev/null @@ -1,197 +0,0 @@ - - - - - diff --git a/cdTMP/src/views/datamanage/dictmanage/index.vue b/cdTMP/src/views/datamanage/dictmanage/index.vue index bfc4974..c27bfeb 100644 --- a/cdTMP/src/views/datamanage/dictmanage/index.vue +++ b/cdTMP/src/views/datamanage/dictmanage/index.vue @@ -32,88 +32,13 @@