WebsiteList.vue 42 KB

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