WebsiteList.vue 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. <template>
  2. <div class="mainBox">
  3. <!--搜索功能 start------------------------------------------------------------>
  4. <div class="layerBox_search">
  5. <div class="layerBoxLine">
  6. <el-row>
  7. <el-col :span="8">
  8. <div class="searchBox">
  9. <div class="searchTitle">网站名称:</div>
  10. <el-input placeholder="请输入网站名称" autocomplete="off" v-model="getApiData.keyword" />
  11. </div>
  12. </el-col>
  13. <el-col :span="8">
  14. <div class="searchBox">
  15. <div class="searchTitle">上级网系:</div>
  16. <el-cascader v-model="getApiData.website_column_id" :props="{ checkStrictly: true }"
  17. :options="website_column_arr" clearable></el-cascader>
  18. </div>
  19. </el-col>
  20. <!-- <el-col :span="8">
  21. <div class="searchBox">
  22. <div class="searchTitle">行政区划:</div>
  23. <CityCascader v-model="getApiData.city_arr_id" @update-city-id="updateCityId"></CityCascader>
  24. </div>
  25. </el-col> -->
  26. </el-row>
  27. </div>
  28. </div>
  29. <div class="layerBoxNoBg">
  30. <div>
  31. <el-button type="primary" @click="addData">添加网站</el-button>
  32. </div>
  33. <div>
  34. <el-button type="info" @click="clearSearchList">重置</el-button>
  35. <el-button type="primary" @click="getData('search')">搜索</el-button>
  36. </div>
  37. </div>
  38. <!--搜索功能 end------------------------------------------------------------>
  39. <!--表格内容 start------------------------------------------------------------>
  40. <div class="layerBox">
  41. <tableTitle :name="tableDivTitle" />
  42. <el-row>
  43. <template>
  44. <el-table :data="tableData" style="width: 100%">
  45. <el-table-column fixed prop="index" label="编号" width="50"></el-table-column>
  46. <el-table-column prop="website_name" label="网站名称"></el-table-column>
  47. <el-table-column prop="column_name" label="上级网系"></el-table-column>
  48. <el-table-column label="网站地址">
  49. <template slot-scope="scope">
  50. <div>
  51. <div v-for="(url, index) in scope.row.website_url" :key="index">
  52. {{ url }}
  53. </div>
  54. </div>
  55. </template>
  56. </el-table-column>
  57. <!-- <el-table-column prop="city_name" label="行政区划"></el-table-column> -->
  58. <el-table-column prop="created_at" label="创建时间"></el-table-column>
  59. <el-table-column prop="updated_at" label="修改时间"></el-table-column>
  60. <el-table-column fixed="right" label="操作" width="240" header-align="center">
  61. <template slot-scope="scope">
  62. <div class="listBtnBox">
  63. <div class="listDeleteBtn" @click="deleteData(scope.row.id, tableData)"><i
  64. class="el-icon-delete"></i>删除</div>
  65. <div class="listEditBtn" @click="getDataMain(scope.row.id, tableData)"><i
  66. class="el-icon-edit-outline"></i>编辑</div>
  67. <div class="listUpBtn" @click="cloneWebsite(scope.row.id, tableData)"><i
  68. class="el-icon-copy-document"></i>克隆</div>
  69. <!-- <div class="listMainBtn" @click="creatWebsite(scope.row.id)"><i class="el-icon-brush"></i>模板</div> -->
  70. </div>
  71. <!-- <div class="listMainBtn"><i class="el-icon-view"></i>详情</div> -->
  72. <!-- <el-button @click.native.prevent="deleteData(scope.row.id, tableData)" type="text" size="small">删除</el-button>
  73. <el-button @click.native.prevent="getDataMain(scope.row.id, tableData)" type="text" size="small">编辑</el-button> -->
  74. </template>
  75. </el-table-column>
  76. </el-table>
  77. </template>
  78. </el-row>
  79. </div>
  80. <div class="alignBox">
  81. <el-row>
  82. <el-col :span="24">
  83. <el-pagination :current-page="getApiData.page" @size-change="handleSizeChange"
  84. @current-change="handleCurrentChange" :page-size="10" layout="total, prev, pager, next, jumper"
  85. :total="allCount"></el-pagination>
  86. </el-col>
  87. </el-row>
  88. </div>
  89. <!--表格内容 end------------------------------------------------------------>
  90. <!--弹出框1:外部表单弹出框 start------------------------------------------------------------>
  91. <el-dialog :title="editId ? '编辑网站' : '添加网站'" :visible.sync="windowStatus" :close-on-click-modal="false">
  92. <!--弹出框2:内部模板弹出框 start------------------------------------------------------------>
  93. <el-dialog width="39%" title="皮肤库" :visible.sync="innerVisible" append-to-body>
  94. <div class="templateBox">
  95. <div class="templateListClass">
  96. <div class="templateListClassItem">简约现代</div>
  97. <div class="templateListClassItem">复古风格</div>
  98. <div class="templateListClassItem">扁平化</div>
  99. </div>
  100. <div class="templateListBox">
  101. <div v-for="item in TemplateList" class="templateList"
  102. @click="useThatTemplate(item.id, item.template_name, item.template_img)">
  103. <img :src="item.template_img" class="templateImg">
  104. <div>{{ item.template_name }}</div>
  105. </div>
  106. </div>
  107. </div>
  108. <div class="pageNumBox">
  109. <el-pagination @size-change="handleTemplateSize" @current-change="handleChangeCurrent" :page-size="10"
  110. layout="total, prev, pager, next, jumper" :total="TemplateallCount"></el-pagination>
  111. </div>
  112. <div class="webSiteBtn">
  113. <el-button type="primary" @click="innerVisible = false">确 定</el-button>
  114. </div>
  115. </el-dialog>
  116. <!--弹出框2:内部模板弹出框 end------------------------------------------------------------>
  117. <el-form :model="form" ref="form" :rules="formRules" autocomplete="off" label-position="left">
  118. <div class="formDiv">
  119. <el-form-item label="网站名称:" :label-width="formLabelWidth" prop="website_name" class="custom-align-right">
  120. <el-input v-model="form.website_name" autocomplete="off" @blur="checkWebsiteName(form.website_name)"
  121. placeholder="请输入网站名称"></el-input>
  122. </el-form-item>
  123. <el-form-item label="网站地址1:" :label-width="formLabelWidth" prop="website_url[0].url"
  124. class="custom-align-right">
  125. <div class="formLabelFloatBox">
  126. <el-input v-model="form.website_url[0].url" autocomplete="off"
  127. @blur="checkWebsiteUrl(form.website_url[0].url, 0)" placeholder="请输入网站地址1"></el-input>
  128. <el-button type="info" icon="el-icon-plus" circle size="mini" @click="addUrlInput(1)"
  129. class="formLabeladdIcon"></el-button>
  130. <el-button type="info" icon="el-icon-delete" circle size="mini" @click="" class="formLabelDelIcon"
  131. disabled></el-button>
  132. </div>
  133. </el-form-item>
  134. <el-form-item label="网站地址2:" :label-width="formLabelWidth" v-if="form.website_url[1].show == true"
  135. class="custom-align-right">
  136. <div class="formLabelFloatBox">
  137. <el-input v-model="form.website_url[1].url" autocomplete="off"
  138. @blur="checkWebsiteUrl(form.website_url[1].url, 1)" placeholder="请输入网站地址2"></el-input>
  139. <el-button type="info" icon="el-icon-plus" circle size="mini" @click="addUrlInput(2)"
  140. class="formLabeladdIcon"></el-button>
  141. <el-button type="info" icon="el-icon-delete" circle size="mini" @click="deleteUrlInput(1)"
  142. class="formLabelDelIcon"></el-button>
  143. </div>
  144. </el-form-item>
  145. <el-form-item label="网站地址3:" :label-width="formLabelWidth" v-if="form.website_url[2].show == true"
  146. class="custom-align-right">
  147. <div class="formLabelFloatBox">
  148. <el-input v-model="form.website_url[2].url" autocomplete="off"
  149. @blur="checkWebsiteUrl(form.website_url[2].url, 2)" placeholder="请输入网站地址3"></el-input>
  150. <el-button type="info" icon="el-icon-plus" circle size="mini" @click="addUrlInput(3)"
  151. class="formLabeladdIcon"></el-button>
  152. <el-button type="info" icon="el-icon-delete" circle size="mini" @click="deleteUrlInput(2)"
  153. class="formLabelDelIcon"></el-button>
  154. </div>
  155. </el-form-item>
  156. <el-form-item label="网站地址4:" :label-width="formLabelWidth" v-if="form.website_url[3].show == true"
  157. class="custom-align-right">
  158. <div class="formLabelFloatBox">
  159. <el-input v-model="form.website_url[3].url" autocomplete="off"
  160. @blur="checkWebsiteUrl(form.website_url[3].url, 3)" placeholder="请输入网站地址4"></el-input>
  161. <el-button type="info" icon="el-icon-plus" circle size="mini" @click="addUrlInput(4)"
  162. class="formLabeladdIcon"></el-button>
  163. <el-button type="info" icon="el-icon-delete" circle size="mini" @click="deleteUrlInput(3)"
  164. class="formLabelDelIcon"></el-button>
  165. </div>
  166. </el-form-item>
  167. <el-form-item label="网站地址5:" :label-width="formLabelWidth" v-if="form.website_url[4].show == true"
  168. class="custom-align-right">
  169. <div class="formLabelFloatBox">
  170. <el-input v-model="form.website_url[4].url" autocomplete="off"
  171. @blur="checkWebsiteUrl(form.website_url[4].url, 4)" placeholder="请输入网站地址5"></el-input>
  172. <el-button type="info" icon="el-icon-plus" circle size="mini" @click="" class="formLabeladdIcon"
  173. disabled></el-button>
  174. <el-button type="info" icon="el-icon-delete" circle size="mini" @click="deleteUrlInput(4)"
  175. class="formLabelDelIcon"></el-button>
  176. </div>
  177. </el-form-item>
  178. <el-form-item label="上级网系:" :label-width="formLabelWidth" prop="website_column_arr_id"
  179. class="custom-align-right">
  180. <el-cascader v-model="form.website_column_arr_id" :props="{ checkStrictly: true }"
  181. :options="website_column_arr"></el-cascader>
  182. </el-form-item>
  183. <!-- <el-form-item label="行政区划:" :label-width="formLabelWidth" prop="city_arr_id" class="custom-align-right">
  184. <CityCascader v-model="form.city_arr_id" @update-city-id="updateFormCityId"></CityCascader>
  185. </el-form-item> -->
  186. <el-form-item label="网站logo:" prop="logo" :label-width="formLabelWidth" :class="['custom-form-item']"
  187. class="custom-align-right">
  188. <div class="uploaderBox">
  189. <!-- <el-upload class="avatar-uploader" action="#" :show-file-list="false" :before-upload="beforeAvatarUpload">
  190. <img v-if="logoUrl" :src="logoUrl" class="avatar">
  191. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  192. </el-upload> -->
  193. <!--图片上传组件 start ------------------------------------------------------------>
  194. <div class="avatar-upload-container" @mouseenter="hovering = true" @mouseleave="hovering = false">
  195. <!-- 上传组件 -->
  196. <el-upload class="avatar-uploader" action="#" :show-file-list="false"
  197. :before-upload="beforeAvatarUpload">
  198. <!-- 预览图片 -->
  199. <img v-if="logoUrl" :src="logoUrl" class="avatar">
  200. <!-- 上传图标 -->
  201. <!-- <i v-else class="el-icon-plus avatar-uploader-icon"></i> -->
  202. <div v-else class="chooseImgDiv">
  203. <div>
  204. <img src="@/assets/public/upload/noImage.png">
  205. <div>选择图片</div>
  206. </div>
  207. </div>
  208. <input type="hidden" name="logo" v-model="form.logo">
  209. </el-upload>
  210. <!-- 删除按钮,当鼠标悬浮时显示 -->
  211. <div v-if="hovering && logoUrl" class="delete-button" @click="handleDelete">
  212. <i class="el-icon-delete"></i>
  213. </div>
  214. </div>
  215. <!--图片上传组件 end ------------------------------------------------------------>
  216. </div>
  217. </el-form-item>
  218. <el-form-item label="网站标题:" :label-width="formLabelWidth" prop="title" class="custom-align-right">
  219. <template #label>
  220. <span class="askBox">
  221. 网站标题:
  222. <el-tooltip class="item" effect="dark" content="网站标题,如:三农市场网_网站列表_全国信息一体化网络平台_项目大全。" placement="top">
  223. <i class="el-icon-question"></i>
  224. </el-tooltip>
  225. </span>
  226. </template>
  227. <el-input v-model="form.title" autocomplete="off" placeholder="请输入网站标题"></el-input>
  228. </el-form-item>
  229. <el-form-item label="网站关键词:" :label-width="formLabelWidth" prop="keywords" class="custom-align-right">
  230. <template #label>
  231. <span class="askBox">
  232. 网站关键词:
  233. <el-tooltip class="item" effect="dark" content="网站关键词,如:三农市场网、全国三农、信息一体化。" placement="top">
  234. <i class="el-icon-question"></i>
  235. </el-tooltip>
  236. </span>
  237. </template>
  238. <!-- <el-input v-model="form.keywords" autocomplete="off" placeholder="请输入网站关键词"></el-input> -->
  239. <inputTag :initialTags="tags" @tags-updated="updateTags" />
  240. </el-form-item>
  241. <el-form-item label="网站描述:" :label-width="formLabelWidth" prop="description" class="custom-align-right">
  242. <template #label>
  243. <span class="askBox">
  244. 网站描述:
  245. <el-tooltip class="item" effect="dark" content="网站描述,如:中国三农市场网创建以来,社会效益和会员经济效益贡献。" placement="top">
  246. <i class="el-icon-question"></i>
  247. </el-tooltip>
  248. </span>
  249. </template>
  250. <el-input type="textarea" v-model="form.description" class="custom-textarea"
  251. placeholder="请输入网站描述"></el-input>
  252. </el-form-item>
  253. <el-form-item label="网站后缀:" :label-width="formLabelWidth" prop="suffix" class="custom-align-right">
  254. <template #label>
  255. <span class="askBox">
  256. 网站后缀:
  257. <el-tooltip class="item" effect="dark" content="网站后缀,如:全国政务信息一体化应用平台" placement="top">
  258. <i class="el-icon-question"></i>
  259. </el-tooltip>
  260. </span>
  261. </template>
  262. <el-input type="textarea" v-model="form.suffix" class="custom-textarea" placeholder="请输入网站后缀"></el-input>
  263. </el-form-item>
  264. <!-- <el-form-item label="模板:" :label-width="formLabelWidth" class="custom-align-right" prop="template_id">
  265. <div class="webSiteTemplate" @click="getTemplateList">
  266. <div class="webSiteTemplateImg">
  267. <div>
  268. <img v-if="TemplateImg" :src="TemplateImg" class="selectWebSiteTemplateImg">
  269. <div v-else>
  270. <img src="@/assets/public/upload/noImage.png">
  271. <div class="webSiteTemplateText">皮肤库</div>
  272. </div>
  273. <input type="hidden" name="template_id" v-model="form.template_id">
  274. </div>
  275. </div>
  276. </div>
  277. </el-form-item> -->
  278. </div>
  279. </el-form>
  280. <div slot="footer" class="dialog-footer">
  281. <div class="footerBtnbox">
  282. <el-button @click="closeWindow" type="info">取 消</el-button>
  283. <el-button type="primary" @click="editToServe" v-if="editBtn == true">确定</el-button>
  284. <el-button type="primary" @click="addToServe" v-else>提交</el-button>
  285. </div>
  286. </div>
  287. </el-dialog>
  288. <!--弹出框2:外部表单弹出框 end------------------------------------------------------------>
  289. </div>
  290. </template>
  291. <script>
  292. //本地编译城市代码
  293. //import getLocationNameById from '@/utils/citytocode';
  294. //城市级联选择器
  295. import CityCascader from './components/CityCascader';
  296. //表格标题
  297. import tableTitle from './components/tableTitle';
  298. //引入公用样式
  299. import '@/styles/global.less';
  300. import InputTag from '@/components/InputTag'
  301. export default {
  302. components: {
  303. CityCascader, //城市级联选择器
  304. tableTitle,//表格标题
  305. InputTag
  306. },
  307. data() {
  308. //0.全局操作 start ------------------------------------------------------------>
  309. //表单验证
  310. const validateEmpty = (rule, value, callback) => {
  311. if (value.length == 0) {
  312. callback(new Error('该项不能为空!'))
  313. } else {
  314. callback()
  315. }
  316. }
  317. const validateWebsiteUrl = (rule, value, callback) => {
  318. if (!value || value.trim() === "") {
  319. callback(new Error('至少要填写一个网站地址!'));
  320. } else {
  321. callback();
  322. }
  323. }
  324. const validateColumn = (rule, value, callback) => {
  325. if (value.length === 0) {
  326. callback(new Error('该项不能为空!'))
  327. } else {
  328. callback()
  329. }
  330. }
  331. let self = this;
  332. //0.全局操�� end ------------------------------------------------------------>
  333. return {
  334. tags: [],
  335. //1.列表和分页相关 start ------------------------------------------------------------>
  336. tableDivTitle: "网站列表",
  337. tableData: [],//内容
  338. editId: 0,//要修改的网站id
  339. getApiData: {
  340. keyword: "",//网站名称查询
  341. website_column_id: [],//使用网系id查询
  342. city_id: [],//使用城市id查询
  343. page: 1,//当前是第几页
  344. pageSize: 10,//一共多少条
  345. },
  346. allCount: 0,//总条数
  347. //分页相关 end ------------------------------------------------------------>
  348. //2.弹出框设置 start ------------------------------------------------------------>
  349. windowStatus: false, //显示第一层弹窗
  350. innerVisible: false, //显示第二层弹窗
  351. formLabelWidth: '120px',//表单的长度
  352. editBtn: false,//当显示编辑按钮的时候,就不显示提交
  353. //弹出框设置 start ------------------------------------------------------------>
  354. //3.弹出框中的表单设置 start ------------------------------------------------------------>
  355. //3.1 表单收集的数据
  356. form: {
  357. website_name: '',//需要提交的网站名称
  358. website_url: [//需要绑定的网站地址
  359. { url: "", show: true },
  360. { url: "", show: false },
  361. { url: "", show: false },
  362. { url: "", show: false },
  363. { url: "", show: false }
  364. ],
  365. website_column_arr_id: [],//需要提交的上级网系 数组
  366. //city_arr_id:[0],//需要提交的城市id
  367. logo: "",//logo地址 提交文件换取地址
  368. title: "",//需要提交的网站标题
  369. keywords: "",//需要提交的网站标题
  370. description: "",//需要提交的网站描述
  371. suffix: "",//需要提交的网站后缀
  372. //template_id:""//选择的网站皮肤
  373. },
  374. //3.2 表单验证规则
  375. formRules: {
  376. //网站名称不能为空
  377. website_name: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  378. //网站地址不能为空
  379. 'website_url[0].url': [
  380. { required: true, message: '至少要填写一个网站地址!', trigger: 'blur' },
  381. { validator: this.validateWebsiteUrl, trigger: 'blur' }
  382. ],
  383. //网系不能为空 注意,因为是select框,只有提交的时候才会验证
  384. website_column_arr_id: [{ type: 'array', required: true, trigger: 'change', message: '必须选择一个网系!', validator: validateColumn }],
  385. //网站标题,关键词,描述不能为空
  386. //city_arr_id:[{required:true,trigger:'blur',validator:validateColumn}],
  387. title: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  388. keywords: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  389. description: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  390. logo: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  391. logoUrl: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  392. suffix: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  393. //template_id:[{required:true,trigger:'blur',validator:validateEmpty}],
  394. },
  395. //3.3 通过api获的的数据 弹窗
  396. website_column_arr: [],//api获得的网系列表
  397. //3.4 上传logo图片
  398. logoUrl: '',
  399. hovering: false, // 鼠标悬浮状态 悬浮时显示删除
  400. //3.5 模板列表
  401. TemplateList: [],
  402. getTemplateData: {
  403. template_class_id: 1,//模板类型,暂时为1
  404. page: 1,//当前是第几页
  405. pageSize: 9,//请求多少条
  406. },
  407. TemplateallCount: 0,//总条数
  408. TemplateName: "未选择模板..",//选择的模板名称
  409. TemplateImg: "",//选择的模板图片
  410. //弹出框中的表单设置 end ------------------------------------------------------------>
  411. }
  412. },
  413. methods: {
  414. //1.列表和分页相关 start ------------------------------------------------------------>
  415. //1.1 开始请求列表信息方法
  416. getData(type) {
  417. //搜索条件 - 网系和城市id只提交最后一个
  418. if (this.getApiData.website_column_id.length > 0) {
  419. this.getApiData.website_column_id = this.getApiData.website_column_id[this.getApiData.website_column_id.length - 1];
  420. }
  421. if (this.getApiData.city_id.length > 0) {
  422. this.getApiData.city_id = this.getApiData.city_id[this.getApiData.city_id.length - 1];
  423. }
  424. //如果是搜索,重新加载第一页
  425. if (type == "search") {
  426. this.getApiData.page = 1;
  427. }
  428. //console.log(this.getApiData)
  429. this.$store.dispatch('pool/getWebList', this.getApiData).then(res => {
  430. let newData = [];
  431. //显示原有的id
  432. // for(let item of res.data.rows){
  433. // if(item.city_name==null){item.city_name="--"}
  434. // newData.push(item)
  435. // }
  436. //显示1-10编号
  437. for (let i = 0; i < res.data.rows.length; i++) {
  438. newData[i] = res.data.rows[i];
  439. newData[i].index = i + 1;
  440. }
  441. console.log(newData)
  442. //格式化网站地址
  443. // res.data.rows.forEach(item => {
  444. // item.website_url = item.website_url.join(', ');
  445. // });
  446. this.tableData = newData; //给与内容
  447. this.allCount = res.data.count; //给与总条数
  448. }).catch(() => {
  449. this.$message({
  450. type: 'warning',
  451. message: '网络错误,请重试!'
  452. });
  453. })
  454. },
  455. //1.2 删除内容
  456. deleteData(id) {
  457. this.$confirm('删除后,该条信息及其绑定关系全部删除,确定吗?', '提示', {
  458. confirmButtonText: '确定',
  459. cancelButtonText: '取消',
  460. type: 'warning'
  461. }).then(() => {
  462. console.log("当前删除:" + id)
  463. this.$store.dispatch('pool/deleteWebList', { id: id }).then(res => {
  464. this.getData();
  465. this.$message({
  466. type: 'success',
  467. message: '删除成功!'
  468. });
  469. }).catch(() => {
  470. this.$message({
  471. type: 'warning',
  472. message: '网络错误,请重试!'
  473. });
  474. })
  475. }).catch(() => {
  476. this.$message({
  477. type: 'warning',
  478. message: '已取消删除'
  479. });
  480. });
  481. },
  482. //1.3 列表内容分页
  483. //直接跳转
  484. handleSizeChange(val) {
  485. this.getApiData.page = val;
  486. this.getData();
  487. },
  488. //1.4 点击分页
  489. handleCurrentChange(val) {
  490. this.getApiData.page = val;
  491. this.getData();
  492. },
  493. //1.6 重置按钮
  494. clearSearchList() {
  495. this.tableData = [];
  496. this.getApiData.keyword = "";
  497. this.getApiData.website_column_id = [];
  498. this.getApiData.city_id = [];
  499. //this.getApiData.city_arr_id = [];
  500. this.getApiData.page = 1;
  501. this.getApiData.pageSize = 10;
  502. this.getData();
  503. },
  504. //1.7搜索栏的城市选择器
  505. updateCityId(value) {
  506. // 这里可以处理选择后的回调逻辑
  507. console.log("城市ID已更新:", value);
  508. // 可以在此处执行额外逻辑
  509. this.getApiData.city_id = value;
  510. },
  511. //列表和分页相关 end ------------------------------------------------------------>
  512. //2.弹出框设置 start ------------------------------------------------------------>
  513. //2.1 打开弹出框
  514. openWindow() {
  515. this.clearToServe();
  516. this.windowStatus = true;
  517. },
  518. //2.2 关闭弹出框
  519. closeWindow() {
  520. this.windowStatus = false;
  521. this.clearToServe();
  522. },
  523. //2.3 重置窗口内容
  524. clearToServe() {
  525. //还原表单
  526. this.form.website_name = "";
  527. this.form.website_column_arr_id = "";
  528. this.form.website_url = [
  529. { url: "", show: true },
  530. { url: "", show: false },
  531. { url: "", show: false },
  532. { url: "", show: false },
  533. { url: "", show: false }
  534. ];
  535. //this.form.city_arr_id = [0];
  536. this.form.logo = "";
  537. this.form.title = "";
  538. this.form.keywords = "";
  539. this.form.description = "";
  540. this.form.template_id = "";
  541. //还原logo缩略图
  542. this.logoUrl = "";
  543. //还原模板
  544. this.TemplateList = [];
  545. this.getTemplateData.page = 1;
  546. this.TemplateImg = "";
  547. this.TemplateallCount = 0;
  548. this.form.suffix = "";
  549. this.form.keywords = "";
  550. this.tags = [];
  551. },
  552. //弹出框设置 end ------------------------------------------------------------>
  553. //3.添加新网站 start ------------------------------------------------------------>
  554. //3.1 获得所有网系
  555. getwebsiteColumn() {
  556. let that = this;
  557. this.$store.dispatch('pool/getwebsiteColumn').then(res => {
  558. let arrData = this.transformData(res.data)
  559. this.website_column_arr = arrData;
  560. })
  561. },
  562. transformData(arrData) {
  563. let that = this;
  564. return arrData.map(item => {
  565. // 创建一个新的对象,替换键名
  566. let newItem = {
  567. label: item.column_name,
  568. value: item.id,
  569. // 保留其他不需要改动的字段
  570. pid: item.pid,
  571. sort: item.sort,
  572. remark: item.remark,
  573. column_arr_id: item.column_arr_id,
  574. updated_at: item.updated_at,
  575. created_at: item.created_at,
  576. };
  577. // 如果有 children,则递归处理 children 数组
  578. if (item.children && item.children.length > 0) {
  579. newItem.children = that.transformData(item.children);
  580. }
  581. return newItem;
  582. });
  583. },
  584. //3.2 开始添加内容
  585. addData() {
  586. this.$router.push({
  587. path: '/addWebsite',
  588. });
  589. // //先获取所有网系
  590. // this.getwebsiteColumn()
  591. // //显示网系到弹出窗口
  592. // this.openWindow()
  593. // //修改添加和编辑窗口的文字提示
  594. // this.editId = 0;
  595. // //显示提交按钮
  596. // this.editBtn = false;
  597. //清除错误状态
  598. this.$refs.form.clearValidate();
  599. },
  600. //3.3 添加一条网站地址
  601. addUrlInput(key) {
  602. this.form.website_url[key].show = true;
  603. },
  604. //3.4 删除一条网站地址
  605. deleteUrlInput(key) {
  606. this.form.website_url[key].show = false;
  607. this.form.website_url[key].url = "";
  608. },
  609. //3.5 弹出框的城市选择器
  610. updateFormCityId(value) {
  611. //console.log("城市ID已更新:", value);
  612. //this.form.city_arr_id = value;
  613. },
  614. //3.6 上传图片操作
  615. beforeAvatarUpload(file) {
  616. const isJPG = file.type === 'image/jpeg';
  617. const isPNG = file.type === 'image/png';
  618. const isLt2M = file.size / 1024 / 1024 < 2;
  619. if (!isJPG && !isPNG) {
  620. this.$message.error('上传头像图片只能是 JPG 或 PNG 格式!');
  621. return false;
  622. }
  623. if (!isLt2M) {
  624. this.$message.error('上传头像图片大小不能超过 2MB!');
  625. return false;
  626. }
  627. const formData = new FormData();
  628. formData.append('file', file);
  629. this.$store.dispatch('pool/uploadFile', formData).then(res => {
  630. this.logoUrl = res.data.imgUrl;//显示缩略图
  631. this.form.logo = res.data.imgUrl;//提供表单地址
  632. console.log(res.data.imgUrl)
  633. }).catch(() => {
  634. this.$message({
  635. type: 'warning',
  636. message: '网络错误,请重试!'
  637. });
  638. })
  639. // 阻止默认的上传行为
  640. return false;
  641. },
  642. handleDelete() {
  643. // 删除图片
  644. this.logoUrl = ''; // 清空图片 URL
  645. },
  646. //3.7 提交表单
  647. addToServe() {
  648. console.log(this.form)
  649. //先进行验证
  650. this.$refs.form.validate(valid => {
  651. if (valid) {
  652. //提交之前把域名列表转换成数组
  653. let webSiteArray = [];
  654. for (let item of this.form.website_url) {
  655. if (item.url != "") {
  656. webSiteArray.push(item.url)
  657. }
  658. }
  659. //循环完毕 重置提交的url
  660. this.form.website_url = webSiteArray;
  661. //console.log(webSiteArray)
  662. console.log(this.form)
  663. //提交表单
  664. this.$store.dispatch('pool/addWebsite', this.form).then(res => {
  665. if (res.code == 200) {
  666. //汇报结果
  667. this.$message({
  668. type: 'success',
  669. message: '已成功添加网站!'
  670. });
  671. //重新获取表单
  672. this.getData();
  673. //清空并退出
  674. this.closeWindow();
  675. } else {
  676. this.$message({
  677. type: 'error',
  678. message: '添加失败!请检查网络!'
  679. });
  680. //清空并退出
  681. this.closeWindow();
  682. }
  683. }).catch(() => {
  684. this.$message({
  685. type: 'warning',
  686. message: '网络错误,请重试!'
  687. });
  688. })
  689. }
  690. })
  691. },
  692. //3.8 检测网站名称是否存在
  693. checkWebsiteName(name) {
  694. let data = {
  695. website_name: name
  696. }
  697. if (this.editId != "") {
  698. data.id = this.editId;
  699. }
  700. this.$store.dispatch('pool/checkWebsiteName', data).then(res => {
  701. if (res.code == 200) {
  702. this.form.website_name = "";
  703. this.$message({
  704. type: 'warning',
  705. message: '网站名称已存在!请重新输入!'
  706. });
  707. }
  708. })
  709. },
  710. //3.9 检测网站url是否存在
  711. checkWebsiteUrl(url, num) {
  712. let data = {
  713. website_url: url
  714. }
  715. if (this.editId != "") {
  716. data.id = this.editId;
  717. }
  718. this.$store.dispatch('pool/checkWebsiteUrl', data).then(res => {
  719. if (res.code == 200) {
  720. if (num == 0) { this.form.website_url[0].url = "" }
  721. if (num == 1) { this.form.website_url[1].url = "" }
  722. if (num == 2) { this.form.website_url[2].url = "" }
  723. if (num == 3) { this.form.website_url[3].url = "" }
  724. if (num == 4) { this.form.website_url[4].url = "" }
  725. this.$message({
  726. type: 'warning',
  727. message: '当前网站已经被占用,请重新输入!'
  728. });
  729. }
  730. })
  731. },
  732. //添加新网站 end ------------------------------------------------------------>
  733. //4.选择模板 start ------------------------------------------------------------>
  734. //4.1 获取模板列表
  735. getTemplateList() {
  736. //先打开弹出框
  737. this.innerVisible = true;
  738. //获取模板列表
  739. this.$store.dispatch('pool/getTemplate', this.getTemplateData).then(res => {
  740. //直接给与数据
  741. //this.TemplateList = res.data.rows;
  742. //格式化 目前缩略图给了两张,我只展示其中一张
  743. let data = res.data.rows;
  744. for (let item of data) {
  745. //item.template_img
  746. let imgSrc = item.template_img;
  747. item.template_img = imgSrc[0];
  748. }
  749. this.TemplateList = data;
  750. //给与总条数
  751. this.TemplateallCount = res.data.count;
  752. }).catch(() => {
  753. this.$message({
  754. type: 'warning',
  755. message: '网络错误,请重试!'
  756. });
  757. })
  758. },
  759. //4.2 选择一个模板
  760. useThatTemplate(id, template_name, template_img) {
  761. console.log(template_name);
  762. console.log(template_img);
  763. // 关闭弹出框
  764. this.innerVisible = false;
  765. // 显示用户选择的名称
  766. this.TemplateName = template_name;
  767. // 确保这里设置了 TemplateImg
  768. this.TemplateImg = template_img; // 确保 template_img 是有效的路径
  769. // 记录选择的模板id
  770. this.form.template_id = id;
  771. },
  772. //4.1 模板列表分页
  773. //直接跳转
  774. handleTemplateSize(val) {
  775. this.getTemplateData.page = val;
  776. this.getTemplateList();
  777. },
  778. //4.2 点击分页
  779. handleChangeCurrent(val) {
  780. this.getTemplateData.page = val;
  781. this.getTemplateList();
  782. },
  783. //选择模板 end ------------------------------------------------------------>
  784. //5.编辑网站 start ------------------------------------------------------------>
  785. //5.1获取详情
  786. getDataMain(id) {
  787. this.$router.push({
  788. path: '/addwebsite',
  789. query: { id: id }
  790. });
  791. //先清空窗口
  792. this.clearToServe()
  793. //打开输入窗口
  794. // this.openWindow();
  795. //添加修改id
  796. // this.editId = id;
  797. //获取网站详情
  798. // this.$store.dispatch('pool/getWebsiteInfo', { id: id }).then(res => {
  799. // //清除错误状态
  800. // this.$refs.form.clearValidate();
  801. // console.log(res)
  802. // //回显网站名称
  803. // this.form.website_name = res.data.website_name;
  804. // //回显星系
  805. // this.form.website_column_arr_id = res.data.website_column_arr_id;
  806. // //回显logo
  807. // this.form.logo = res.data.logo;
  808. // this.logoUrl = res.data.logo;
  809. // //回显url
  810. // let that = this;
  811. // if (res.data.website_url == null) {
  812. // //为null什么都不执行
  813. // } else {
  814. // for (let index in res.data.website_url) {
  815. // this.form.website_url[index].url = res.data.website_url[index];
  816. // this.form.website_url[index].show = true;
  817. // }
  818. // }
  819. // //回显id
  820. // //存放城市id
  821. // //this.form.city_arr_id = res.data.city_arr_id;
  822. // //当cascaderKey的值改变的时候 级联选择器会重置里面的内容
  823. // //this.cascaderKey += 1;
  824. // //回显网站标题,描述,关键词
  825. // console.log(res.data.title, res.data.keywords, res.data.description)
  826. // this.form.title = res.data.title;
  827. // this.form.keywords = res.data.keywords;
  828. // this.tags = res.data.keywords ? res.data.keywords.split(',') : [];
  829. // this.form.description = res.data.description;
  830. // this.form.suffix = res.data.suffix;
  831. // //回显模板信息
  832. // // this.form.template_id = res.data.template_id;
  833. // // this.TemplateName = res.data.template_name;
  834. // // this.TemplateImg = JSON.parse(res.data.template_img)[0];
  835. // })
  836. this.editBtn = true;//显示编辑按钮
  837. },
  838. //5.2修改表单
  839. editToServe() {
  840. //执行验证
  841. this.$refs.form.validate(valid => {
  842. if (valid) {
  843. //提交之前把域名列表转换成数组
  844. let webSiteArray = [];
  845. for (let item of this.form.website_url) {
  846. if (item.url != "") {
  847. webSiteArray.push(item.url)
  848. }
  849. }
  850. //循环完毕 重置提交的url
  851. this.form.website_url = webSiteArray;
  852. this.form.id = this.editId;
  853. //提交表单
  854. this.$store.dispatch('pool/updateWebsite', this.form).then(res => {
  855. console.log(res.code)
  856. if (res.code == 200) {
  857. //汇报结果
  858. this.$message({
  859. type: 'success',
  860. message: '已成功修改网站信息!'
  861. });
  862. //清空并退出
  863. this.closeWindow();
  864. //重新请求列表
  865. this.getData();
  866. } else {
  867. this.$message.error('修改失败!')
  868. //清空并退出
  869. this.closeWindow();
  870. }
  871. }).catch(() => {
  872. this.$message({
  873. type: 'warning',
  874. message: '网络错误,请重试!'
  875. });
  876. })
  877. }
  878. })
  879. },
  880. //编辑旧网站 end ------------------------------------------------------------>
  881. //6.搭建网站 start ------------------------------------------------------------>
  882. creatWebsite(id) {
  883. this.$router.push({
  884. path: '/templateBase',
  885. query: { id: id }
  886. });
  887. },
  888. updateTags(newTags) {
  889. // this.foem.seo_keywords = newTags;
  890. this.tags = newTags;
  891. this.form.keywords = newTags.join(',');
  892. },
  893. //编辑旧网站 end ------------------------------------------------------------>
  894. //克隆网站
  895. cloneWebsite(id) {
  896. this.$confirm('克隆后,将生成一个一摸一样的网站,确定吗?', '提示', {
  897. confirmButtonText: '确定',
  898. cancelButtonText: '取消',
  899. type: 'warning'
  900. }).then(() => {
  901. console.log("当前克隆:" + id)
  902. this.$store.dispatch('pool/cloneWebsite', { website_id: id }).then(res => {
  903. this.getData();
  904. this.$message({
  905. type: 'success',
  906. message: '克隆成功!'
  907. });
  908. }).catch(() => {
  909. this.$message({
  910. type: 'warning',
  911. message: '网络错误,请重试!'
  912. });
  913. })
  914. }).catch(() => {
  915. this.$message({
  916. type: 'warning',
  917. message: '已取消克隆'
  918. });
  919. });
  920. },
  921. },
  922. mounted() {
  923. //1.获得初始数据
  924. this.getData();
  925. //2.获取所有网系
  926. this.getwebsiteColumn();
  927. //本地转换id为文字
  928. //console.log(getLocationNameById("110000"))
  929. }
  930. }
  931. </script>
  932. <style scoped lang="less">
  933. /*表单特殊样式 start------------------------------------------------------------>*/
  934. //1.1 模板表单
  935. .webSite {
  936. background: #f0f2f5;
  937. width: 200px;
  938. height: 300px;
  939. line-height: 300px;
  940. text-align: center;
  941. margin: 0 auto;
  942. }
  943. .webSiteTemplate {
  944. display: flex;
  945. .webSiteTitle {
  946. width: 120px;
  947. line-height: 140px;
  948. text-align: right;
  949. padding-right: 12px;
  950. font-weight: bold;
  951. }
  952. }
  953. .webSiteBtn {
  954. padding: 50px 0 0 0;
  955. text-align: center;
  956. }
  957. .formLabelFloatBox {
  958. position: relative;
  959. .formLabeladdIcon {
  960. position: absolute;
  961. right: 45px;
  962. top: 5px;
  963. width: 38px;
  964. height: 24px;
  965. }
  966. .formLabelDelIcon {
  967. position: absolute;
  968. right: 5px;
  969. top: 5px;
  970. width: 38px;
  971. height: 24px;
  972. }
  973. }
  974. .templateBox {
  975. display: flex;
  976. .templateListClass {
  977. margin-right: 20px;
  978. .templateListClassItem {
  979. width: 120px;
  980. height: 38px;
  981. text-align: center;
  982. line-height: 38px;
  983. border: 1px solid #E3E8FA;
  984. background: #F5F7FB;
  985. margin-bottom: 10px;
  986. border-radius: 8px;
  987. cursor: pointer;
  988. }
  989. }
  990. .templateListBox {
  991. box-sizing: border-box;
  992. width: 100%;
  993. display: flex;
  994. flex-wrap: wrap;
  995. .templateList {
  996. margin-right: 10px;
  997. text-align: center;
  998. font-size: 12px;
  999. margin-bottom: 10px;
  1000. border: 1px solid #fff;
  1001. padding: 5px;
  1002. .templateImg {
  1003. width: 129px;
  1004. height: 157px;
  1005. border-radius: 8px;
  1006. cursor: pointer;
  1007. }
  1008. }
  1009. }
  1010. }
  1011. //1.1 模板分页
  1012. .pageNumBox {
  1013. text-align: center;
  1014. padding-top: 20px;
  1015. }
  1016. .webSiteTemplateName {
  1017. margin-left: 10px;
  1018. line-height: 36px;
  1019. }
  1020. //1.2 模板缩略图
  1021. .webSiteTemplateImg {
  1022. width: 140px;
  1023. height: 140px;
  1024. cursor: pointer;
  1025. display: flex;
  1026. align-items: center;
  1027. justify-content: center;
  1028. border-radius: 12px;
  1029. border: 1px solid #E1E2E9;
  1030. .selectWebSiteTemplateImg {
  1031. width: 140px;
  1032. height: 140px;
  1033. border-radius: 12px;
  1034. display: block;
  1035. cursor: pointer;
  1036. }
  1037. .webSiteTemplateText {
  1038. color: #5570F1;
  1039. height: 36px;
  1040. line-height: 36px;
  1041. text-align: center;
  1042. }
  1043. img {
  1044. display: block;
  1045. }
  1046. }
  1047. /*表单样式 end------------------------------------------------------------>*/
  1048. //执行v-deep穿透scope选择器 start------------------------------------------------------------>*/
  1049. ::v-deep .custom-form-item>.el-form-item__label {
  1050. line-height: 140px !important;
  1051. }
  1052. ::v-deep .custom-textarea .el-textarea__inner {
  1053. resize: none;
  1054. /* 禁止用户拖拽调整大小 */
  1055. }
  1056. ::v-deep .custom-align-right .el-form-item__label {
  1057. text-align: right;
  1058. /* 设置标签文字右对齐 */
  1059. }
  1060. //执行v-deep穿透scope选择器 end------------------------------------------------------------>*/</style>