123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834 |
- <template>
- <!-- 友情链接列表 -->
- <div>
- <div class="title">
- <el-row>
- <el-col :span="6" class="left">
- <div class="searchBox">
- <div class="searchTitle">所属站点</div>
- <el-select v-model="siteName" :multiple="false" :multiple-limit="1" filterable remote
- reserve-keyword placeholder="请输入所属站点" :remote-method="getWebNavList"
- :loading="webSiteLoading" @change="selectWebSite">
- <el-option v-for="item in webSiteList" :key="item.value" :label="item.label"
- :value="item.value">
- </el-option>
- </el-select>
- </div>
- </el-col>
- <el-col :span="6" class="left">
- <div class="searchBox">
- <div class="searchTitle">链接名称</div>
- <el-input v-model="webName" placeholder="请输入链接名称"></el-input>
- </div>
- </el-col>
- <el-col :span="10" class="right">
- <div class="btnList">
- <button class="search" @click="goSearch">搜索</button>
- <button class="reset" @click="reset">重置</button>
- </div>
- </el-col>
- </el-row>
- </div>
- <!--表格内容 start------------------------------------------------------------>
- <div class="layerBox">
- <tableTitle :name="tableDivTitle" />
- <button class="btn" @click="addWebsite">添加链接</button>
- <el-row>
- <template>
- <el-table class="my-table" :data="tableData" style="width: 100%">
- <el-table-column fixed prop="id" label="编号" width="70">
- </el-table-column>
- <el-table-column prop="website_name" label="关联网站" width="180">
- </el-table-column>
- <el-table-column prop="title" label="链接名称" width="160">
- </el-table-column>
- <el-table-column prop="url" label="链接网址" width="180">
- </el-table-column>
- <el-table-column prop="type" label="类型" width="90">
- </el-table-column>
- <el-table-column label="网站LOGO" width="150">
- <template slot-scope="scope">
- <img :src="scope.row.logo_url" alt="" class="uploadImage">
- </template>
- </el-table-column>
- <el-table-column prop="sort" label="排序" width="90">
- </el-table-column>
- <el-table-column prop="created_at" label="创建时间" width="180">
- </el-table-column>
- <el-table-column prop="updated_at" label="修改时间" width="180">
- </el-table-column>
- <el-table-column fixed="right" label="操作" width="220">
- <template slot-scope="scope">
- <div class="listBtnBox">
- <div class="listDeleteBtn" @click="deleteRow(scope.row.id, scope.row)">
- <i class="el-icon-delete"></i>删除
- </div>
- <div class="listEditBtn" @click="goEdit(scope.row.id, scope.row)">
- <i class="el-icon-edit-outline"></i>编辑
- </div>
- </div>
- </template>
- </el-table-column>
- </el-table>
- </template>
- </el-row>
- </div>
- <!--分页 start------------------------------------------------------------>
- <div class="alignBox">
- <el-row>
- <el-col :span="24">
- <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
- :current-page="page" :page-size="pageSize" layout="total, prev, pager, next, jumper"
- :total="total">
- </el-pagination>
- </el-col>
- </el-row>
- </div>
- <!--分页 end------------------------------------------------------------>
- <!--表格内容 end------------------------------------------------------------>
- <!-- 弹出框 start------------------------------------------------------------>
- <el-dialog :title="dialogName" :visible.sync="dialogTableVisible" width="50%" :close-on-click-modal="false">
- <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
- <div class="dialogText">
- <el-form-item label="关联网站:" prop="correlationWeb">
- <el-select v-model="ruleForm.correlationWeb" :multiple="false" :multiple-limit="1" filterable
- remote reserve-keyword placeholder="请输入关联网站名称" :remote-method="getWebNavList"
- :loading="webSiteLoading" @change="detectionWebSite">
- <el-option v-for="item in webSiteList" :key="item.value" :label="item.label"
- :value="item.value">
- </el-option>
- </el-select>
- </el-form-item>
- <el-form-item label="链接名称:" prop="webName">
- <el-input v-model="ruleForm.webName" placeholder="请输入链接名称"></el-input>
- </el-form-item>
- <el-form-item label="链接地址:" prop="webUrl">
- <el-input v-model="ruleForm.webUrl" placeholder="请输入链接地址"></el-input>
- </el-form-item>
- <el-form-item label="类型:" prop="type">
- <el-radio v-model="ruleForm.type" label="1">图片</el-radio>
- <el-radio v-model="ruleForm.type" label="2">文本</el-radio>
- <el-radio v-model="ruleForm.type" label="3">底部</el-radio>
- </el-form-item>
- <el-form-item label="网站logo:" prop="" :label-width="formLabelWidth" :class="['custom-form-item']"
- class="custom-align-right" v-show="this.ruleForm.type != '2'">
- <div class="uploaderBox">
- <!--图片上传组件 start ------------------------------------------------------------>
- <div class="avatar-upload-container" @mouseenter="hovering = true"
- @mouseleave="hovering = false">
- <!-- 上传组件 -->
- <el-upload class="avatar-uploader" action="#" :show-file-list="false"
- :before-upload="beforeAvatarUpload">
- <!-- 预览图片 -->
- <img v-if="logoUrl" :src="logoUrl" class="avatar">
- <!-- 上传图标 -->
- <div v-else class="chooseImgDiv">
- <div>
- <img src="@/assets/public/upload/noImage.png">
- <div>选择图片</div>
- </div>
- </div>
- <input type="hidden" name="logo" v-model="ruleForm.webLogo">
- </el-upload>
- <!-- 删除按钮,当鼠标悬浮时显示 -->
- <div v-if="hovering && logoUrl" class="delete-button" @click="handleDelete">
- <i class="el-icon-delete"></i>
- </div>
- </div>
- <!--图片上传组件 end ------------------------------------------------------------>
- </div>
- </el-form-item>
- <el-form-item label="网站介绍:" prop="">
- <el-input v-model="ruleForm.webDesc" type="textarea" :rows="3" placeholder="请输入网站介绍"
- resize="none">
- </el-input>
- </el-form-item>
- <el-form-item label="排序:" prop="sort">
- <el-input v-model="ruleForm.sort" placeholder="请输入排序"></el-input>
- </el-form-item>
- </div>
- <div class="dialogBtn">
- <!-- <button class="cancel" @click="cancelForm">取消</button>
- <button class="submit" @click="submitFormTow">提交</button> -->
- <el-button type="info" @click="cancelForm">取消</el-button>
- <el-button type="primary" @click="submitForm">提交</el-button>
- </div>
- </el-form>
- </el-dialog>
- <!-- 弹出框 end------------------------------------------------------------>
- </div>
- </template>
- <script>
- //表格标题
- import tableTitle from './components/blogroll/tableTitle.vue';
- //引入公用样式
- import '@/styles/global.less';
- // 引入api
- import { getLinkInfo, getLinkList, createLink, delLink, updateLink } from '@/api/link.js'
- export default {
- components: {
- tableTitle,//表格标题
- },
- data() {
- const validateEmpty = (rule, value, callback) => {
- if (value.length == 0) {
- callback(new Error('该项不能为空!'))
- } else {
- callback()
- }
- }
- return {
- tableDivTitle: "友情链接列表", //表格标题
- webName: '', // 网站名称
- activeId: '', // 被编辑的网站的id
- activeType: '', //被编辑网站的type
- disabled: true, //是否禁用
- //搜索相关
- siteName: '', //所属站点
- webName: '', //网站名称
- //3.4 上传logo图片
- logoUrl: '',
- hovering: false, // 鼠标悬浮状态 悬浮时显示删除
- // 分页器相关
- total: 0,
- page: 1,
- pageSize: 10,
- //表格相关
- tableData: [],
- //弹出框相关
- dialogTableVisible: false, //是否显示
- dialogName: '', //弹框标题名
- // 可以输入的搜索框相关
- webSiteList: [],//获取关联网站列表
- webSiteLoading: false,
- options: [],
- value: [],
- list: [],
- value: '',
- radio: '1',
- textarea: '',
- // 图片相关
- formLabelWidth: '120px',//表单的长度
- website_id: "",
- //表单相关
- ruleForm: {
- correlationWeb: '', //关联网站
- webName: '', //网站名称
- webUrl: '', //网站地址
- type: '1', //类型
- webLogo: '', //网站logo
- webDesc: '', //网站介绍
- sort: '', //排序
- },
- rules: { //规则
- correlationWeb: [{ required: true, trigger: 'blur', validator: validateEmpty }], //关联网站
- webName: [{ required: true, trigger: 'blur', validator: validateEmpty }],
- webUrl: [{ required: true, trigger: 'blur', validator: validateEmpty }],
- type: [{ required: true, trigger: 'blur', validator: validateEmpty }],
- sort: [{ required: true, trigger: 'blur', validator: validateEmpty }]
- },
- }
- },
- methods: {
- //1.列表和分页相关 start ------------------------------------------------------------>
- //1.1 获取网站列表数据
- getData() {
- if (this.siteName || this.webName) {
- getLinkList({
- page: this.page,
- pageSize: this.pageSize,
- website_id: this.siteName,
- title: this.webName
- }).then(data => {
- console.log(data);
- this.tableData = data.data.rows
- this.total = data.data.count
- for (let item of this.tableData) {
- if (item.type == '1') {
- item.type = '图片'
- } else if (item.type == '2') {
- item.type = '文字'
- } else if (item.type == '3') {
- item.type = '底部'
- }
- }
- })
- } else {
- getLinkList({
- page: this.page,
- pageSize: this.pageSize,
- }).then(data => {
- console.log(data);
- this.tableData = data.data.rows
- this.total = data.data.count
- for (let item of this.tableData) {
- if (item.type == '1') {
- item.type = '图片'
- } else if (item.type == '2') {
- item.type = '文字'
- } else if (item.type == '3') {
- item.type = '底部'
- }
- }
- })
- }
- },
- //1.2 删除内容
- deleteRow(id, val) {
- this.activeId = id
- this.$confirm('注意:删除后,该条信息及其绑定关系全部删除', '是否确认删除该条信息?', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- }).then(() => {
- console.log("当前删除:" + id)
- delLink({
- id: this.activeId,
- }).then(data => {
- console.log(data);
- if (data.code == 200) {
- this.$message({
- type: 'success',
- message: '删除成功!'
- });
- this.getData()
- } else if (data.code == 0) {
- this.$message({
- type: 'error',
- message: data.message
- });
- }
- })
- }).catch(() => {
- this.$message({
- type: 'warning',
- message: '已取消'
- });
- });
- },
- //1.3 列表内容分页
- //直接跳转
- handleSizeChange(val) {
- this.page = val;
- this.getData();
- },
- //1.4 点击分页
- handleCurrentChange(val) {
- this.page = val;
- this.getData();
- },
- // 1.5 搜索按钮
- goSearch() {
- getLinkList({
- page: this.page,
- pageSize: this.pageSize,
- website_id: this.siteName,
- title: this.webName
- }).then(data => {
- console.log(data);
- this.tableData = data.data.rows
- this.total = data.data.count
- for (let item of this.tableData) {
- if (item.type == '1') {
- item.type = '图片'
- } else if (item.type == '2') {
- item.type = '文字'
- } else if (item.type == '3') {
- item.type = '底部'
- }
- }
- })
- },
- //1.6 重置按钮
- reset() {
- this.siteName = ''
- this.webName = ''
- this.getData()
- },
- //列表和分页相关 end ------------------------------------------------------------>
- //1.7 添加
- addWebsite() {
- this.dialogTableVisible = true //弹窗是否显示
- this.dialogName = "添加" //弹窗名称
- this.ruleForm.correlationWeb = ''
- this.ruleForm.webName = ''
- this.ruleForm.webUrl = ''
- this.ruleForm.type = '1'
- this.logoUrl = 'http://183.131.25.186:9501/image/20241225/17350893036168.png'
- this.ruleForm.webLogo = 'http://183.131.25.186:9501/image/20241225/17350893036168.png'
- this.ruleForm.webDesc = ''
- this.ruleForm.sort = 0
- },
- //1.8 编辑
- goEdit(id, val) {
- this.dialogTableVisible = true //弹框显示
- this.dialogName = "编辑" //弹框名字
- console.log(id, val);
- this.activeId = id //活动id
- this.website_id = val.website_id //网站id
- this.ruleForm.correlationWeb = val.website_name
- this.ruleForm.webName = val.title
- this.ruleForm.webUrl = val.url
- this.ruleForm.webLogo = val.logo_url
- this.logoUrl = val.logo_url
- this.ruleForm.webDesc = val.describe
- this.ruleForm.sort = val.sort
- if (val.type == "图片") {
- this.ruleForm.type = '1'
- } else if (val.type == "文字") {
- this.ruleForm.type = '2'
- } else if (val.type == "底部") {
- this.ruleForm.type = '3'
- }
- },
- // 弹出层相关方法
- // 提交表单
- submitForm() {
- // console.log(123)
- if (this.ruleForm.correlationWeb == '') {
- this.$message.error("请输入并选择关联网站名称");
- return
- }
- // 添加
- if (this.dialogName == "添加") {
- if (this.ruleForm.type == '2') {
- createLink({
- title: this.ruleForm.webName,
- website_id: this.website_id,
- sort: this.ruleForm.sort,
- url: this.ruleForm.webUrl,
- type: this.ruleForm.type,
- logo_url: '',
- describe: this.ruleForm.webDesc
- }).then(data => {
- console.log(data);
- if (data.code == 200) {
- this.$message({
- message: "添加成功",
- type: 'success'
- });
- this.dialogTableVisible = false
- this.getData()
- } else {
- this.$message.error(data.message)
- }
- })
- } else {
- createLink({
- title: this.ruleForm.webName,
- website_id: this.website_id,
- sort: this.ruleForm.sort,
- url: this.ruleForm.webUrl,
- type: this.ruleForm.type,
- logo_url: this.ruleForm.webLogo,
- describe: this.ruleForm.webDesc
- }).then(data => {
- console.log(data);
- if (data.code == 200) {
- this.$message({
- message: "添加成功",
- type: 'success'
- });
- this.dialogTableVisible = false
- this.getData()
- } else {
- this.$message.error(data.message)
- }
- })
- }
- }
- if (this.dialogName == "编辑") {
- if (this.website_id == " ") {
- this.$message.error("请输入并选择关联网站");
- this.dialogTableVisible = true
- return
- }
- if (this.ruleForm.type == '2') {
- updateLink({
- title: this.ruleForm.webName,
- website_id: this.website_id,
- sort: this.ruleForm.sort,
- url: this.ruleForm.webUrl,
- type: this.ruleForm.type,
- logo_url: '',
- describe: this.ruleForm.webDesc,
- id: this.activeId,
- }).then(data => {
- console.log(data);
- if (data.code == 200) {
- this.$message({
- message: "修改成功",
- type: 'success'
- })
- this.dialogTableVisible = false
- this.getData()
- } else {
- this.$message({
- message: data.message,
- type: 'error'
- })
- }
- })
- } else {
- updateLink({
- title: this.ruleForm.webName,
- website_id: this.website_id,
- sort: this.ruleForm.sort,
- url: this.ruleForm.webUrl,
- type: this.ruleForm.type,
- logo_url: this.ruleForm.webLogo,
- describe: this.ruleForm.webDesc,
- id: this.activeId,
- }).then(data => {
- console.log(data);
- if (data.code == 200) {
- this.$message({
- message: "修改成功",
- type: 'success'
- })
- this.dialogTableVisible = false
- this.getData()
- } else {
- this.$message({
- message: data.message,
- type: 'error'
- })
- }
- })
- }
- }
- },
- //取消添加或编辑
- cancelForm() {
- this.dialogTableVisible = false
- },
- //3.6 上传图片操作
- beforeAvatarUpload(file) {
- console.log(file);
- // this.ruleForm.webLogo=file
- const isJPG = file.type === 'image/jpeg';
- const isPNG = file.type === 'image/png';
- const isLt2M = file.size / 1024 / 1024 < 2;
- if (!isJPG && !isPNG) {
- this.$message.error('上传头像图片只能是 JPG 或 PNG 格式!');
- return false;
- }
- if (!isLt2M) {
- this.$message.error('上传头像图片大小不能超过 2MB!');
- return false;
- }
- const formData = new FormData();
- formData.append('file', file);
- this.$store.dispatch('pool/uploadFile', formData).then(res => {
- console.log('res', res);
- this.logoUrl = res.data.imgUrl;//显示缩略图
- this.ruleForm.webLogo = res.data.imgUrl;//提供表单地址
- console.log(res.data.imgUrl)
- }).catch(() => {
- this.$message({
- type: 'info',
- message: '网络错误,请重试!'
- });
- })
- // 阻止默认的上传行为
- return false;
- },
- handleDelete() {
- // 删除图片
- this.logoUrl = ''; // 清空图片 URL
- },
- //搜索部分的输入关键词下拉框
- selectWebSite(value) {
- this.siteName = value
- },
- //添加 / 编辑弹窗中输入关键词下拉框
- // 判断是否已经关联了网站
- detectionWebSite(value) {
- console.log(value);
- this.website_id = value
- // let data = {
- // website_id: value
- // }
- //验证一下是不是存在了关联网站名称
- // this.$store.dispatch('pool/getAdminWebsiteCategory', data).then(res => {
- // if (res.data.length > 0) {
- // this.ruleForm.webName = "";
- // this.$message({
- // type: 'warning',
- // message: '该网站已经关联了导航,请重新选择!'
- // });
- // }
- // })
- },
- //
- getWebNavList(query) {
- if (query !== '') {
- this.webSiteLoading = true;
- let data = { keyword: query }
- let dataArr = [];
- this.$store.dispatch('pool/getNavWebList', data).then(res => {
- console.log(res.data)
- for (let item of res.data) {
- let data = {};
- data.key = item.id;
- data.value = item.id;
- data.label = item.website_name;
- dataArr.push(data)
- }
- this.webSiteList = dataArr;
- this.webSiteLoading = false;
- }).catch(() => {
- this.$message({
- type: 'info',
- message: '网络错误,请重试!'
- });
- })
- } else {
- this.navList = [];
- }
- },
- },
- mounted() {
- //获取网站列表数据
- this.getData()
- }
- }
- </script>
- <style scoped lang="less">
- .title {
- margin: 30px 30px 20px 30px;
- padding: 30px 30px 40px 30px;
- background-color: #fff;
- border-radius: 20px 20px 20px 20px;
- border: 1px solid #E9EDF7;
- .left {
- float: left;
- }
- .right {
- float: right;
- }
- .searchBox {
- .searchTitle {
- padding-bottom: 10px;
- font-family: Microsoft YaHei, Microsoft YaHei;
- font-weight: 400;
- font-size: 14px;
- color: #999999;
- line-height: 16px;
- }
- .el-select {
- width: 85%;
- display: inline-block;
- position: relative;
- }
- }
- .btnList {
- float: right;
- padding-top: 28px;
- button {
- width: 120px;
- height: 38px;
- border: none;
- border-radius: 8px;
- // padding: 0 30px;
- }
- .search {
- background-color: #5570f1;
- color: #fff;
- margin-right: 20px;
- }
- .reset {
- font-family: Microsoft YaHei, Microsoft YaHei;
- font-weight: 400;
- font-size: 16px;
- color: #333333;
- background: #F5F7FB;
- border-radius: 8px 8px 8px 8px;
- border: 1px solid rgba(85, 112, 241, 0.11);
- }
- }
- }
- .layerBox {
- padding: 30px 20px;
- position: relative;
- .btn {
- position: absolute;
- top: 30px;
- right: 20px;
- height: 38px;
- color: #fff;
- background-color: #5570f1;
- border: none;
- border-radius: 8px;
- padding: 8px 28px 9px;
- box-sizing: border-box;
- }
- .listBtnBox {
- justify-content: left;
- }
- .listDeleteBtn,
- .listEditBtn,
- .listLookBtn {
- margin-left: 0px;
- padding-left: 0px;
- margin-right: 20px;
- width: 76px;
- height: 36px;
- line-height: 36px;
- }
- .listLookBtn {
- text-align: center;
- border-radius: 8px;
- cursor: pointer;
- color: #55b5f1;
- background-color: rgba(85, 181, 241, 0.16);
- >i {
- padding-right: 8px;
- }
- }
- .uploadImage {
- width: 130px;
- }
- // from表单中每条数据的下外边距
- ::v-deep .el-form-item {
- margin-bottom: 50px;
- }
- //下拉框宽度
- ::v-deep .el-select {
- width: 100%;
- }
- ::v-deep .el-input--medium,
- ::v-deep .el-form-item__label {
- line-height: 36px;
- font-size: 16px;
- }
- }
- // 弹出层内容
- .dialogText {
- margin: 0 7px 0 3px;
- padding-top: 20px;
- padding-bottom: 1px;
- padding: 20px 60px 1px 20px;
- background-color: #f5f7fb;
- // from表单中每条数据的下外边距
- ::v-deep .el-form-item {
- margin-bottom: 50px;
- }
- //下拉框宽度
- ::v-deep .el-select {
- width: 100%;
- }
- //图片的宽高
- ::v-deep .avatar {
- width: 140px;
- height: auto;
- }
- .keywords {
- position: relative;
- i {
- position: absolute;
- top: 0;
- left: -15px;
- }
- }
- }
- // 弹出层按钮
- .dialogBtn {
- text-align: center;
- margin: 50px auto 20px;
- ::v-deep .avatar {
- width: 140px;
- height: 50px;
- display: block;
- }
- button {
- width: 184px;
- padding: 16px;
- font-family: Microsoft YaHei, Microsoft YaHei;
- font-weight: 400;
- font-size: 20px;
- border: none;
- border-radius: 12px 12px 12px 12px;
- }
- // 取消
- .cancel {
- color: #333333;
- background-color: #f5f7fb;
- border: 2px solid rgba(85, 112, 241, 0.11);
- }
- // 提交
- .submit {
- color: #fff;
- background-color: #5570F1;
- margin-left: 40px;
- }
- }
- </style>
|