WebsiteList.vue 37 KB

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