1.链接接口联调

sws 2024-08-20
v1.0.0
sws 2024-08-20 15:46:49 +08:00
parent d72f6b7b43
commit 12de19a7fb
11 changed files with 243 additions and 168 deletions

View File

@ -8,6 +8,47 @@ class UrlValueAPI {
method: 'post',
});
}
/** 获取商品列表 */
static getGoodsList(data: any) {
return request({
url: `diyapi/goodslist`,
method: 'post',
data,
});
}
/** 获取文章列表 */
static getArticleList(data: any) {
return request({
url: `diyapi/articlelist`,
method: 'post',
data,
});
}
/** 获取diy列表 */
static getDiyList(data: any) {
return request({
url: `diyapi/diylist`,
method: 'post',
data,
});
}
/** 获取页面设计列表 */
static getDesignList(data: any) {
return request({
url: `diyapi/designlist`,
method: 'post',
data,
});
}
/** 获取自定义列表 */
static getCustomList(data: any) {
return request({
url: `diyapi/customviewlist`,
method: 'post',
data,
});
}
}
export default UrlValueAPI;

View File

@ -1,5 +1,5 @@
<template>
<el-image :src="image?.url || ''" class="flex align-c jc-c" @load="on_load">
<el-image :src="is_obj(image) ? image?.url || '' : image" class="flex align-c jc-c" @load="on_load">
<template #error>
<div class="image-slot" :style="errorStyle">
<img :src="error_image" :style="errorImgStyle" />
@ -8,6 +8,7 @@
</el-image>
</template>
<script setup lang="ts">
import { is_obj } from '@/utils';
const props = defineProps({
errorImgStyle: {
type: String,
@ -18,7 +19,7 @@ const props = defineProps({
default: () => '',
},
});
const image = defineModel({ type: Object, default: () => {} });
const image = defineModel({ type: [Object, String], default: () => {} });
const error_image = ref(new URL(`../../../assets/images/empty.png`, import.meta.url).href);
const emit = defineEmits(['load']);
const on_load = (e: any) => {
@ -34,5 +35,8 @@ const on_load = (e: any) => {
align-items: center;
justify-content: center;
background-color: #f4fcff;
img {
width: 100%;
}
}
</style>

View File

@ -2,7 +2,7 @@
<template>
<div class="flex-row align-c gap-10 br-d radius-sm plr-11 url-value-input" @click="dialogVisible = true">
<div class="flex-1 flex-width size-12 text-line-1">
<text v-if="!is_obj_empty(modelValue)">{{ modelValue.name }}</text>
<text v-if="!is_obj_empty(modelValue)">{{ modelValue.name || modelValue.title }}</text>
<text v-else class="cr-9">{{ placeholder }}</text>
</div>
<div class="value-input-icon">

View File

@ -2,43 +2,45 @@
<!-- 商品分类 -->
<div class="container">
<div class="flex-row jc-e gap-20 mb-20">
<el-select v-model="type" class="search-w" placeholder="请选择">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
<el-select v-model="category_ids" class="search-w" placeholder="请选择" clearable @change="handle_search">
<el-option v-for="item in article_category_list" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
<el-input v-model="search_value" placeholder="请输入搜索内容" class="search-w" @change="handle_search">
<template #suffix>
<icon name="search" size="16" color="9"></icon>
<icon name="search" size="16" color="9" class="c-pointer" @click="handle_search"></icon>
</template>
</el-input>
</div>
<div class="content">
<el-table :data="tableData" class="w" :header-cell-style="{ background: '#f7f7f7' }" row-key="id" height="438" fixed @row-click="row_click">
<el-table-column label="#" width="120" type="">
<el-table-column label="#" width="40" type="">
<template #default="scope">
<el-radio v-model="template_selection" :label="scope.$index + ''">&nbsp;</el-radio>
</template>
</el-table-column>
<el-table-column prop="id" label="ID" width="180" type="" />
<el-table-column prop="icon" label="文章图片" width="130">
<el-table-column prop="id" label="ID" width="80" type="" />
<el-table-column prop="cover" label="文章">
<template #default="scope">
<el-image :src="scope.row.icon" class="img">
<template #error>
<div class="bg-f5 flex-row jc-c align-c radius h w">
<icon name="error-img" size="14" color="9"></icon>
</div>
</template>
</el-image>
<div class="flex-row align-c gap-10">
<image-empty v-model="scope.row.cover" class="img"></image-empty>
<div class="flex-1">{{ scope.row.title }}</div>
</div>
</template>
</el-table-column>
<el-table-column prop="name" label="文章名称" />
<template #empty>
<no-data></no-data>
</template>
</el-table>
<div class="mt-10 flex-row jc-e">
<el-pagination :current-page="page" :page-size="21" :pager-count="5" layout="prev, pager, next" :total="data_total" @current-change="get_list" />
<el-pagination :current-page="page" :page-size="page_size" :pager-count="5" layout="prev, pager, next" :total="data_total" @current-change="get_list" />
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import UrlValueAPI from '@/api/url-value';
import { urlValueStore, urlValue, pageLinkList } from '@/store';
const url_value_store = urlValueStore();
const props = defineProps({
//
reset: {
@ -49,70 +51,59 @@ const props = defineProps({
watch(
() => props.reset,
() => {
template_selection.value = '';
init();
}
);
onMounted(() => {
init();
});
const modelValue = defineModel({ type: Object, default: {} });
const tableData: linkData[] = [
{
id: 1,
name: '一级分类一级分类一级分类一级分类一级分类一级分类一级分类',
icon: 'https://img.yzcdn.cn/vant/cat.jpeg',
link: 'a',
},
{
id: 3,
name: '一级分类',
icon: 'https://img.yzcdn.cn/vant/cat.jpeg',
link: 'c',
},
{
id: 4,
name: '一级分类',
icon: 'https://img.yzcdn.cn/vant/cat.jpeg',
link: 'd',
},
{
id: 5,
name: '一级分类',
icon: 'https://img.yzcdn.cn/vant/cat.jpeg',
link: 'e',
},
];
const tableData = ref<pageLinkList[]>([]);
const search_value = ref('');
const handle_search = () => {
console.log(search_value.value);
const init = () => {
template_selection.value = '';
category_ids.value = '';
search_value.value = '';
article_category_list.value = url_value_store.url_value.article_category_list;
get_list(1);
};
const type = ref('');
const options = ref([
{ value: '1', label: '一级分类' },
{ value: '2', label: '二级分类' },
{ value: '3', label: '三级分类' },
]);
const handle_search = () => {
get_list(1);
};
const category_ids = ref('');
interface articleCategory {
id: string;
name: string;
url: string;
}
const article_category_list = ref<articleCategory[]>([]);
const template_selection = ref('');
const row_click = (row: any) => {
const new_table_data = JSON.parse(JSON.stringify(tableData));
const new_table_data = JSON.parse(JSON.stringify(tableData.value));
template_selection.value = new_table_data.findIndex((item: linkData) => item.id == row.id).toString();
modelValue.value = row;
};
//#region -----------------------------------------------start
//
// const page_total = ref(0);
//
const page = ref(1);
//
const page_size = ref(10);
//
const data_total = ref(0);
//
const search_data = ref({
page: page.value,
type: '',
name: search_value.value,
});
//
const get_list = () => {
console.log('查询接口', search_data);
const get_list = (new_page: number) => {
let new_data = {
page: new_page,
keywords: search_value.value,
category_ids: category_ids.value,
page_size: page_size.value,
};
UrlValueAPI.getArticleList(new_data).then((res: any) => {
tableData.value = res.data.data_list;
data_total.value = res.data.data_total;
page.value = res.data.page;
});
};
//#region -----------------------------------------------end
</script>

View File

@ -48,6 +48,7 @@
</template>
<script lang="ts" setup>
import type { FormInstance } from 'element-plus';
import { pageLinkList } from '@/store';
const props = defineProps({
status: {
type: Boolean,
@ -128,12 +129,12 @@ const address = computed(() => {
return { trigger: 'change', message: '详细地址不能为空', required: custom_type_active.value == 3 };
});
const ruleFormRef = ref<FormInstance>();
const emit = defineEmits(['update:link', 'required']);
const emit = defineEmits(['update:link']);
const on_submit = () => {
if (!ruleFormRef.value) return;
ruleFormRef.value.validate((valid: boolean) => {
if (valid) {
let new_value: linkData = {
let new_value: pageLinkList = {
name: '',
link: '',
};
@ -161,8 +162,6 @@ const on_submit = () => {
};
}
emit('update:link', new_value);
} else {
emit('required');
}
});
};

View File

@ -16,18 +16,15 @@
</template>
</el-table-column>
<el-table-column prop="id" label="ID" width="180" type="" />
<el-table-column prop="name" label="分类名称" />
<el-table-column prop="name" label="分类名称"></el-table-column>
<el-table-column prop="icon" label="分类图标">
<template #default="scope">
<el-image :src="scope.row.icon" class="img">
<template #error>
<div class="img">
<img :src="error_image" class="w" />
</div>
</template>
</el-image>
<image-empty v-model="scope.row.icon" class="img"></image-empty>
</template>
</el-table-column>
<template #empty>
<no-data></no-data>
</template>
</el-table>
</div>
</div>
@ -53,7 +50,6 @@ const modelValue = defineModel({ type: Object, default: {} });
const table_data = ref<pageLinkList[]>([]);
const new_table_data = ref<pageLinkList[]>([]);
const search_value = ref('');
const error_image = ref(new URL(`../../../assets/images/empty.png`, import.meta.url).href);
onMounted(() => {
init();
});

View File

@ -87,7 +87,7 @@ watch(
init();
}
);
const emit = defineEmits(['update:link', 'required', 'type']);
const emit = defineEmits(['update:link', 'type']);
onMounted(() => {
init();
@ -193,8 +193,6 @@ const on_submit = () => {
link: form.key,
};
emit('update:link', new_value, 2);
} else {
emit('required');
}
});
};

View File

@ -2,40 +2,46 @@
<!-- 商品 -->
<div class="container">
<div class="flex-row jc-e gap-20 mb-20">
<el-select v-model="type" class="search-w" placeholder="请选择">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
<el-select v-model="brand" class="search-w" placeholder="品牌">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
<el-cascader v-model="category_ids" :options="category_list" :props="cascader_config" placeholder="请选择" :show-all-levels="false" clearable @change="cascader_change" />
<el-select v-model="brand_ids" class="search-w" placeholder="品牌" clearable @change="handle_search">
<el-option v-for="item in brand_list" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
<el-input v-model="search_value" placeholder="请输入搜索内容" class="search-w" @change="handle_search">
<template #suffix>
<icon name="search" size="16" color="9"></icon>
<icon name="search" size="16" color="9" class="c-pointer" @click="handle_search"></icon>
</template>
</el-input>
</div>
<div class="content">
<el-table :data="tableData" class="w" :header-cell-style="{ background: '#f7f7f7' }" row-key="id" height="438" fixed @row-click="row_click">
<el-table-column label="#" width="120" type="">
<el-table-column label="#" width="40" type="">
<template #default="scope">
<el-radio v-model="template_selection" :label="scope.$index + ''">&nbsp;</el-radio>
</template>
</el-table-column>
<el-table-column prop="id" label="ID" width="180" type="" />
<el-table-column prop="icon" label="商品图片">
<el-table-column prop="id" label="ID" width="80" type="" />
<el-table-column prop="images" label="商品">
<template #default="scope">
<el-image :src="scope.row.icon" class="img" />
<div class="flex-row align-c gap-10">
<image-empty v-model="scope.row.images" class="img"></image-empty>
<div class="flex-1">{{ scope.row.title }}</div>
</div>
</template>
</el-table-column>
<el-table-column prop="name" label="分类名称" />
<el-table-column prop="category_text" width="100" label="分类名称" />
<el-table-column prop="brand_name" width="100" label="品牌名称" />
<template #empty>
<no-data></no-data>
</template>
</el-table>
<div class="mt-10 flex-row jc-e">
<el-pagination :current-page="page" :page-size="21" :pager-count="5" layout="prev, pager, next" :total="data_total" @current-change="get_list" />
<el-pagination :current-page="page" :page-size="page_size" :pager-count="5" layout="prev, pager, next" :total="data_total" @current-change="get_list" />
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import UrlValueAPI from '@/api/url-value';
import { urlValueStore, urlValue, pageLinkList } from '@/store';
const url_value_store = urlValueStore();
const props = defineProps({
@ -57,47 +63,62 @@ onMounted(() => {
const modelValue = defineModel({ type: Object, default: {} });
const tableData = ref<pageLinkList[]>([]);
const search_value = ref('');
const cascader_config = {
value: 'id',
label: 'name',
children: 'items',
};
const init = () => {
template_selection.value = '';
type.value = '';
brand.value = '';
get_list();
category_ids.value = [];
brand_ids.value = '';
search_value.value = '';
category_list.value = url_value_store.url_value.goods_category;
brand_list.value = url_value_store.url_value.brand_list;
get_list(1);
};
const handle_search = () => {
console.log(search_value.value);
get_list(1);
};
const type = ref('');
const brand = ref('');
const options = ref([
{ value: '1', label: '一级分类' },
{ value: '2', label: '二级分类' },
{ value: '3', label: '三级分类' },
]);
const cascader_change = (val: any) => {
// valdatalabel
category_ids.value = val ? val : [];
get_list(1);
};
const category_ids = ref([]);
const brand_ids = ref('');
const category_list = ref<pageLinkList[]>([]);
const brand_list = ref<any[]>([]);
const emit = defineEmits(['update:link']);
const template_selection = ref('');
const row_click = (row: any) => {
const new_table_data = JSON.parse(JSON.stringify(tableData));
template_selection.value = new_table_data.findIndex((item: linkData) => item.id == row.id).toString();
const new_table_data = JSON.parse(JSON.stringify(tableData.value));
template_selection.value = new_table_data.findIndex((item: pageLinkList) => item.id == row.id).toString();
modelValue.value = row;
};
//#region -----------------------------------------------start
//
// const page_total = ref(0);
//
const page = ref(1);
//
const page_size = ref(30);
//
const data_total = ref(0);
//
const search_data = ref({
page: page.value,
type: '',
name: search_value.value,
});
//
const get_list = () => {
console.log('查询接口', search_data);
const get_list = (new_page: number) => {
let new_data = {
page: new_page,
keywords: search_value.value,
brand_ids: brand_ids.value,
page_size: page_size.value,
category_ids: category_ids.value.length > 0 ? category_ids.value[category_ids.value.length - 1] : '',
};
UrlValueAPI.getGoodsList(new_data).then((res: any) => {
tableData.value = res.data.data_list;
data_total.value = res.data.data_total;
page.value = res.data.page;
});
};
//#region -----------------------------------------------end
</script>

View File

@ -4,7 +4,7 @@
<div class="flex-row jc-e gap-20 mb-20">
<el-input v-model="search_value" placeholder="请输入搜索内容" class="search-w" @change="handle_search">
<template #suffix>
<icon name="search" size="16" color="9"></icon>
<icon name="search" size="16" color="9" class="c-pointer" @click="handle_search"></icon>
</template>
</el-input>
</div>
@ -18,15 +18,24 @@
<el-table-column prop="id" label="ID" width="180" type="" />
<el-table-column prop="name" label="页面名称" />
<el-table-column prop="link" label="页面链接" />
<template #empty>
<no-data></no-data>
</template>
</el-table>
<div class="mt-10 flex-row jc-e">
<el-pagination :current-page="page" :page-size="21" :pager-count="5" layout="prev, pager, next" :total="data_total" @current-change="get_list" />
<el-pagination :current-page="page" :page-size="page_size" :pager-count="5" layout="prev, pager, next" :total="data_total" @current-change="get_list" />
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import UrlValueAPI from '@/api/url-value';
import { pageLinkList } from '@/store';
const props = defineProps({
type: {
type: String,
default: () => '',
},
//
reset: {
type: Boolean,
@ -36,61 +45,65 @@ const props = defineProps({
watch(
() => props.reset,
() => {
template_selection.value = '';
init();
}
);
onMounted(() => {
init();
});
const modelValue = defineModel({ type: Object, default: {} });
const tableData: linkData[] = [
{
id: 1,
name: '一级分类',
link: 'a',
},
{
id: 3,
name: '一级分类',
link: 'c',
},
{
id: 4,
name: '一级分类',
link: 'd',
},
{
id: 5,
name: '一级分类',
link: 'e',
},
];
const tableData = ref<pageLinkList[]>([]);
const search_value = ref('');
const init = () => {
template_selection.value = '';
search_value.value = '';
get_list(1);
};
const handle_search = () => {
console.log(search_value.value);
get_list(1);
};
const emit = defineEmits(['update:link']);
const template_selection = ref('');
const row_click = (row: any) => {
const new_table_data = JSON.parse(JSON.stringify(tableData));
template_selection.value = new_table_data.findIndex((item: linkData) => item.id == row.id).toString();
const new_table_data = JSON.parse(JSON.stringify(tableData.value));
template_selection.value = new_table_data.findIndex((item: pageLinkList) => item.id == row.id).toString();
modelValue.value = row;
};
//#region -----------------------------------------------start
//
// const page_total = ref(0);
//
const page = ref(1);
//
const page_size = ref(30);
//
const data_total = ref(0);
//
const search_data = ref({
page: page.value,
type: '',
name: search_value.value,
});
//
const get_list = () => {
console.log('查询接口', search_data);
const get_list = (new_page: number) => {
const new_data = {
page: new_page,
page_size: page_size.value,
keywords: search_value.value,
};
if (props.type == 'diy') {
UrlValueAPI.getDiyList(new_data).then((res: any) => {
tableData.value = res.data.data_list;
data_total.value = res.data.data_total;
page.value = res.data.page;
});
} else if (props.type == 'design') {
UrlValueAPI.getDesignList(new_data).then((res: any) => {
tableData.value = res.data.data_list;
data_total.value = res.data.data_total;
page.value = res.data.page;
});
} else if (props.type == 'custom-view') {
UrlValueAPI.getCustomList(new_data).then((res: any) => {
tableData.value = res.data.data_list;
data_total.value = res.data.data_total;
page.value = res.data.page;
});
}
};
//#region -----------------------------------------------end
</script>

View File

@ -21,19 +21,19 @@
<link-goods-category v-model="link_value" :reset="reset_compontent"></link-goods-category>
</template>
<template v-else-if="link_select == 'goods-search'">
<link-goods-search :reset="reset_compontent" :status="component_status" @update:link="goods_category_link" @type="goods_category_type_change" @required="required_tips"></link-goods-search>
<link-goods-search :reset="reset_compontent" :status="component_status" @update:link="goods_category_link" @type="goods_category_type_change"></link-goods-search>
</template>
<template v-else-if="link_select == 'goods'">
<link-goods v-model="link_value" :reset="reset_compontent"></link-goods>
</template>
<template v-else-if="link_select == 'articles'">
<template v-else-if="link_select == 'article'">
<link-articles v-model="link_value" :reset="reset_compontent"></link-articles>
</template>
<template v-else-if="link_select == 'diy' || link_select == 'design' || link_select == 'custom-view'">
<link-table v-model="link_value" :type="link_select" :reset="reset_compontent"></link-table>
<link-table :key="link_select" v-model="link_value" :type="link_select" :reset="reset_compontent"></link-table>
</template>
<template v-else-if="link_select == 'custom'">
<link-custom :key="link_select" :reset="reset_compontent" :status="component_status" @update:link="custom_link" @required="required_tips"></link-custom>
<template v-else-if="link_select == 'custom-url'">
<link-custom :reset="reset_compontent" :status="component_status" @update:link="custom_link"></link-custom>
</template>
</div>
</div>
@ -137,13 +137,6 @@ const custom_link = (data: object) => {
modelValue.value = data;
close_event();
};
//
const required_tips = () => {
ElMessage({
type: 'warning',
message: '必填项不能为空',
});
};
//#endregion -----------------------------------------------end
//#region -----------------------------------------------start
@ -157,7 +150,7 @@ const close_event = () => {
//
const confirm_event = () => {
//
if (link_select.value == 'custom' || (link_select.value == 'goods-search' && goods_category_type.value == 2)) {
if (link_select.value == 'custom-url' || (link_select.value == 'goods-search' && goods_category_type.value == 2)) {
component_status.value = !component_status.value;
} else {
if (is_obj_empty(link_value.value)) {

View File

@ -12,6 +12,25 @@ import { isEmpty } from 'lodash';
export function is_obj_empty(obj: object): boolean {
return Object.keys(obj).length === 0;
}
/**
*
*
*
* 1. `null` `null` JavaScript
* 2. 使 `typeof`
* 3. 使 `Object.prototype.toString.call(obj)`
*
* @param obj
* @returns true false
*/
export function is_obj(obj: unknown): boolean {
// 特殊处理 null值因为 typeof null 返回 "object",但 null 并不是我们要检查的对象
if (obj === null) return false;
// 使用 typeof 排除非对象类型
if (typeof obj !== 'object') return false;
// 确认是普通对象
return Object.prototype.toString.call(obj) === '[object Object]';
}
/**
*