WebsiteList.vue 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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. logoUrl:[{required:true,trigger:'blur',validator:validateEmpty}],
  345. template_id:[{required:true,trigger:'blur',validator:validateEmpty}],
  346. },
  347. //3.3 通过api获的的数据 弹窗
  348. website_column_arr:[],//api获得的网系列表
  349. //3.4 上传logo图片
  350. logoUrl:'',
  351. hovering: false, // 鼠标悬浮状态 悬浮时显示删除
  352. //3.5 模板列表
  353. TemplateList:[],
  354. getTemplateData:{
  355. template_class_id:1,//模板类型,暂时为1
  356. page:1,//当前是第几页
  357. pageSize:9,//请求多少条
  358. },
  359. TemplateallCount:0,//总条数
  360. TemplateName:"未选择模板..",//选择的模板名称
  361. TemplateImg:"",//选择的模板图片
  362. //弹出框中的表单设置 end ------------------------------------------------------------>
  363. }
  364. },
  365. methods: {
  366. //1.列表和分页相关 start ------------------------------------------------------------>
  367. //1.1 开始请求列表信息方法
  368. getData(type){
  369. //搜索条件 - 网系和城市id只提交最后一个
  370. if(this.getApiData.website_column_id.length>0){
  371. this.getApiData.website_column_id = this.getApiData.website_column_id[this.getApiData.website_column_id.length - 1];
  372. }
  373. if(this.getApiData.city_id.length>0){
  374. this.getApiData.city_id = this.getApiData.city_id[this.getApiData.city_id.length - 1];
  375. }
  376. //如果是搜索,重新加载第一页
  377. if(type=="search"){
  378. this.getApiData.page = 1;
  379. }
  380. //console.log(this.getApiData)
  381. this.$store.dispatch('pool/getWebList',this.getApiData).then(res=> {
  382. let newData = [];
  383. for(let item of res.data.rows){
  384. if(item.city_name==null){item.city_name="--"}
  385. newData.push(item)
  386. }
  387. //格式化网站地址
  388. // res.data.rows.forEach(item => {
  389. // item.website_url = item.website_url.join(', ');
  390. // });
  391. this.tableData = newData; //给与内容
  392. this.allCount = res.data.count; //给与总条数
  393. }).catch(() => {
  394. this.$message({
  395. type: 'info',
  396. message: '网络错误,请重试!'
  397. });
  398. })
  399. },
  400. //1.2 删除内容
  401. deleteData(id){
  402. this.$confirm('此操作将永久删除该条数据, 是否继续?', '提示', {
  403. confirmButtonText: '确定',
  404. cancelButtonText: '取消',
  405. type: 'warning'
  406. }).then(() => {
  407. console.log("当前删除:" + id)
  408. this.$store.dispatch('pool/deleteWebList',{id:id}).then(res=> {
  409. this.getData();
  410. this.$message({
  411. type: 'success',
  412. message: '删除成功!'
  413. });
  414. }).catch(() => {
  415. this.$message({
  416. type: 'warning',
  417. message: '网络错误,请重试!'
  418. });
  419. })
  420. }).catch(() => {
  421. this.$message({
  422. type: 'warning',
  423. message: '已取消删除'
  424. });
  425. });
  426. },
  427. //1.3 列表内容分页
  428. //直接跳转
  429. handleSizeChange(val) {
  430. this.getApiData.page = val;
  431. this.getData();
  432. },
  433. //1.4 点击分页
  434. handleCurrentChange(val) {
  435. this.getApiData.page = val;
  436. this.getData();
  437. },
  438. //1.6 重置按钮
  439. clearSearchList(){
  440. this.tableData = [];
  441. this.getApiData.keyword = "";
  442. this.getApiData.website_column_id = [];
  443. this.getApiData.city_id = [];
  444. this.getApiData.city_arr_id = [];
  445. this.getApiData.page = 1;
  446. this.getApiData.pageSize = 10;
  447. this.getData();
  448. },
  449. //1.7搜索栏的城市选择器
  450. updateCityId(value) {
  451. // 这里可以处理选择后的回调逻辑
  452. console.log("城市ID已更新:", value);
  453. // 可以在此处执行额外逻辑
  454. this.getApiData.city_id = value;
  455. },
  456. //列表和分页相关 end ------------------------------------------------------------>
  457. //2.弹出框设置 start ------------------------------------------------------------>
  458. //2.1 打开弹出框
  459. openWindow() {
  460. this.clearToServe();
  461. this.windowStatus = true;
  462. },
  463. //2.2 关闭弹出框
  464. closeWindow(){
  465. this.windowStatus = false;
  466. this.clearToServe();
  467. },
  468. //2.3 重置窗口内容
  469. clearToServe(){
  470. //还原表单
  471. this.form.website_name = "";
  472. this.form.website_column_arr_id = "";
  473. this.form.website_url = [
  474. {url:"",show:true},
  475. {url:"",show:false},
  476. {url:"",show:false},
  477. {url:"",show:false},
  478. {url:"",show:false}
  479. ];
  480. this.form.city_arr_id = [0];
  481. this.form.logo = "";
  482. this.form.title = "";
  483. this.form.keywords = "";
  484. this.form.description = "";
  485. this.form.template_id = "";
  486. //还原logo缩略图
  487. this.logoUrl = "";
  488. //还原模板
  489. this.TemplateList = [];
  490. this.getTemplateData.page = 1;
  491. this.TemplateImg = "";
  492. this.TemplateallCount = 0;
  493. },
  494. //弹出框设置 end ------------------------------------------------------------>
  495. //3.添加新网站 start ------------------------------------------------------------>
  496. //3.1 获得所有网系
  497. getwebsiteColumn(){
  498. let that = this;
  499. this.$store.dispatch('pool/getwebsiteColumn').then(res=> {
  500. let arrData = this.transformData(res.data)
  501. this.website_column_arr = arrData;
  502. })
  503. },
  504. transformData(arrData) {
  505. let that = this;
  506. return arrData.map(item => {
  507. // 创建一个新的对象,替换键名
  508. let newItem = {
  509. label: item.column_name,
  510. value: item.id,
  511. // 保留其他不需要改动的字段
  512. pid: item.pid,
  513. sort: item.sort,
  514. remark: item.remark,
  515. column_arr_id: item.column_arr_id,
  516. updated_at: item.updated_at,
  517. created_at: item.created_at,
  518. };
  519. // 如果有 children,则递归处理 children 数组
  520. if (item.children && item.children.length > 0) {
  521. newItem.children = that.transformData(item.children);
  522. }
  523. return newItem;
  524. });
  525. },
  526. //3.2 开始添加内容
  527. addData(){
  528. //先获取所有网系
  529. this.getwebsiteColumn()
  530. //显示网系到弹出窗口
  531. this.openWindow()
  532. //显示提交按钮
  533. this.editBtn = false;
  534. //清除错误状态
  535. this.$refs.form.clearValidate();
  536. },
  537. //3.3 添加一条网站地址
  538. addUrlInput(key){
  539. this.form.website_url[key].show=true;
  540. },
  541. //3.4 删除一条网站地址
  542. deleteUrlInput(key){
  543. this.form.website_url[key].show=false;
  544. this.form.website_url[key].url="";
  545. },
  546. //3.5 弹出框的城市选择器
  547. updateFormCityId(value){
  548. console.log("城市ID已更新:", value);
  549. this.form.city_arr_id = value;
  550. },
  551. //3.6 上传图片操作
  552. beforeAvatarUpload(file) {
  553. const isJPG = file.type === 'image/jpeg';
  554. const isPNG = file.type === 'image/png';
  555. const isLt2M = file.size / 1024 / 1024 < 2;
  556. if (!isJPG && !isPNG) {
  557. this.$message.error('上传头像图片只能是 JPG 或 PNG 格式!');
  558. return false;
  559. }
  560. if (!isLt2M) {
  561. this.$message.error('上传头像图片大小不能超过 2MB!');
  562. return false;
  563. }
  564. const formData = new FormData();
  565. formData.append('file', file);
  566. this.$store.dispatch('pool/uploadFile',formData).then(res=> {
  567. this.logoUrl = res.data.imgUrl;//显示缩略图
  568. this.form.logo = res.data.imgUrl;//提供表单地址
  569. console.log(res.data.imgUrl)
  570. }).catch(() => {
  571. this.$message({
  572. type: 'info',
  573. message: '网络错误,请重试!'
  574. });
  575. })
  576. // 阻止默认的上传行为
  577. return false;
  578. },
  579. handleDelete() {
  580. // 删除图片
  581. this.logoUrl = ''; // 清空图片 URL
  582. },
  583. //3.7 提交表单
  584. addToServe(){
  585. console.log(this.form)
  586. //先进行验证
  587. this.$refs.form.validate(valid => {
  588. if (valid) {
  589. //提交之前把域名列表转换成数组
  590. let webSiteArray = [];
  591. for(let item of this.form.website_url){
  592. if(item.url!=""){
  593. webSiteArray.push(item.url)
  594. }
  595. }
  596. //循环完毕 重置提交的url
  597. this.form.website_url = webSiteArray;
  598. //console.log(webSiteArray)
  599. console.log(this.form)
  600. //提交表单
  601. this.$store.dispatch('pool/addWebsite',this.form).then(res=> {
  602. if(res.code==200){
  603. //汇报结果
  604. this.$message({
  605. type: 'success',
  606. message: '已成功添加网站!'
  607. });
  608. //重新获取表单
  609. this.getData();
  610. //清空并退出
  611. this.closeWindow();
  612. }else{
  613. this.$message({
  614. type: 'success',
  615. message: '添加失败!请检查网络!'
  616. });
  617. //清空并退出
  618. this.closeWindow();
  619. }
  620. }).catch(() => {
  621. this.$message({
  622. type: 'info',
  623. message: '网络错误,请重试!'
  624. });
  625. })
  626. }
  627. })
  628. },
  629. //3.8 检测网站名称是否存在
  630. checkWebsiteName(name){
  631. let data = {
  632. website_name:name
  633. }
  634. if(this.editId!=""){
  635. data.id = this.editId;
  636. }
  637. this.$store.dispatch('pool/checkWebsiteName',data).then(res=> {
  638. if(res.code==200){
  639. this.form.website_name = "";
  640. this.$message({
  641. type: 'warning',
  642. message: '网站名称已存在!请重新输入!'
  643. });
  644. }
  645. })
  646. },
  647. //3.9 检测网站url是否存在
  648. checkWebsiteUrl(url,num){
  649. let data = {
  650. website_url:url
  651. }
  652. if(this.editId!=""){
  653. data.id = this.editId;
  654. }
  655. this.$store.dispatch('pool/checkWebsiteUrl',data).then(res=> {
  656. if(res.code==200){
  657. if(num==0){this.form.website_url[0].url=""}
  658. if(num==1){this.form.website_url[1].url=""}
  659. if(num==2){this.form.website_url[2].url=""}
  660. if(num==3){this.form.website_url[3].url=""}
  661. if(num==4){this.form.website_url[4].url=""}
  662. this.$message({
  663. type: 'warning',
  664. message: '当前网站已经被占用,请重新输入!'
  665. });
  666. }
  667. })
  668. },
  669. //添加新网站 end ------------------------------------------------------------>
  670. //4.选择模板 start ------------------------------------------------------------>
  671. //4.1 获取模板列表
  672. getTemplateList(){
  673. //先打开弹出框
  674. this.innerVisible = true;
  675. //获取模板列表
  676. this.$store.dispatch('pool/getTemplate',this.getTemplateData).then(res=> {
  677. //直接给与数据
  678. //this.TemplateList = res.data.rows;
  679. //格式化 目前缩略图给了两张,我只展示其中一张
  680. let data = res.data.rows;
  681. for(let item of data){
  682. //item.template_img
  683. let imgSrc = item.template_img;
  684. item.template_img = imgSrc[0];
  685. }
  686. this.TemplateList = data;
  687. //给与总条数
  688. this.TemplateallCount = res.data.count;
  689. }).catch(() => {
  690. this.$message({
  691. type: 'warning',
  692. message: '网络错误,请重试!'
  693. });
  694. })
  695. },
  696. //4.2 选择一个模板
  697. useThatTemplate(id, template_name, template_img) {
  698. console.log(template_name);
  699. console.log(template_img);
  700. // 关闭弹出框
  701. this.innerVisible = false;
  702. // 显示用户选择的名称
  703. this.TemplateName = template_name;
  704. // 确保这里设置了 TemplateImg
  705. this.TemplateImg = template_img; // 确保 template_img 是有效的路径
  706. // 记录选择的模板id
  707. this.form.template_id = id;
  708. },
  709. //4.1 模板列表分页
  710. //直接跳转
  711. handleTemplateSize(val) {
  712. this.getTemplateData.page = val;
  713. this.getTemplateList();
  714. },
  715. //4.2 点击分页
  716. handleChangeCurrent(val) {
  717. this.getTemplateData.page = val;
  718. this.getTemplateList();
  719. },
  720. //选择模板 end ------------------------------------------------------------>
  721. //5.编辑网站 start ------------------------------------------------------------>
  722. //5.1获取详情
  723. getDataMain(id){
  724. //先清空窗口
  725. this.clearToServe()
  726. //打开输入窗口
  727. this.openWindow();
  728. //添加修改id
  729. this.editId = id;
  730. //获取网站详情
  731. this.$store.dispatch('pool/getWebsiteInfo',{id:id}).then(res=> {
  732. //清除错误状态
  733. this.$refs.form.clearValidate();
  734. console.log(res)
  735. //回显网站名称
  736. this.form.website_name = res.data.website_name;
  737. //回显星系
  738. this.form.website_column_arr_id = res.data.website_column_arr_id;
  739. //回显logo
  740. this.form.logo = res.data.logo;
  741. this.logoUrl = res.data.logo;
  742. //回显url
  743. let that = this;
  744. if(res.data.website_url==null){
  745. //为null什么都不执行
  746. }else{
  747. for(let index in res.data.website_url){
  748. this.form.website_url[index].url = res.data.website_url[index];
  749. this.form.website_url[index].show = true;
  750. }
  751. }
  752. //回显id
  753. //存放城市id
  754. this.form.city_arr_id = res.data.city_arr_id;
  755. //当cascaderKey的值改变的时候 级联选择器会重置里面的内容
  756. //this.cascaderKey += 1;
  757. //回显网站标题,描述,关键词
  758. console.log(res.data.title,res.data.keywords,res.data.description)
  759. this.form.title = res.data.title;
  760. this.form.keywords = res.data.keywords;
  761. this.form.description = res.data.description;
  762. //回显模板信息
  763. this.form.template_id = res.data.template_id;
  764. this.TemplateName = res.data.template_name;
  765. this.TemplateImg = JSON.parse(res.data.template_img)[0];
  766. })
  767. this.editBtn = true;//显示编辑按钮
  768. },
  769. //5.2修改表单
  770. editToServe(){
  771. //执行验证
  772. this.$refs.form.validate(valid => {
  773. if (valid) {
  774. //提交之前把域名列表转换成数组
  775. let webSiteArray = [];
  776. for(let item of this.form.website_url){
  777. if(item.url!=""){
  778. webSiteArray.push(item.url)
  779. }
  780. }
  781. //循环完毕 重置提交的url
  782. this.form.website_url = webSiteArray;
  783. this.form.id = this.editId;
  784. //提交表单
  785. this.$store.dispatch('pool/updateWebsite',this.form).then(res=> {
  786. //汇报结果
  787. this.$message({
  788. type: 'success',
  789. message: '已成功修改网站信息!'
  790. });
  791. //清空并退出
  792. this.closeWindow();
  793. //重新请求列表
  794. this.getData();
  795. }).catch(() => {
  796. this.$message({
  797. type: 'warning',
  798. message: '网络错误,请重试!'
  799. });
  800. })
  801. }
  802. })
  803. },
  804. //编辑旧网站 end ------------------------------------------------------------>
  805. //6.搭建网站 start ------------------------------------------------------------>
  806. creatWebsite(id){
  807. this.$router.push({
  808. path: '/creatWebsite',
  809. query: {id:id}
  810. });
  811. }
  812. //编辑旧网站 end ------------------------------------------------------------>
  813. },
  814. mounted(){
  815. //1.获得初始数据
  816. this.getData();
  817. //2.获取所有网系
  818. this.getwebsiteColumn();
  819. //本地转换id为文字
  820. //console.log(getLocationNameById("110000"))
  821. }
  822. }
  823. </script>
  824. <style scoped lang="less">
  825. /*表单特殊样式 start------------------------------------------------------------>*/
  826. //1.1 模板表单
  827. .webSite {
  828. background:#f0f2f5;
  829. width:200px;
  830. height:300px;
  831. line-height: 300px;
  832. text-align: center;
  833. margin:0 auto;
  834. }
  835. .webSiteTemplate {
  836. display:flex;
  837. .webSiteTitle {
  838. width:120px;
  839. line-height: 140px;
  840. text-align: right;
  841. padding-right:12px;
  842. font-weight: bold;
  843. }
  844. }
  845. .webSiteBtn {
  846. padding:50px 0 0 0;
  847. text-align:center;
  848. }
  849. .formLabelFloatBox {
  850. position: relative;
  851. .formLabeladdIcon {
  852. position: absolute;
  853. right:45px;
  854. top:5px;
  855. width:38px;
  856. height:24px;
  857. }
  858. .formLabelDelIcon {
  859. position: absolute;
  860. right:5px;
  861. top:5px;
  862. width:38px;
  863. height:24px;
  864. }
  865. }
  866. .templateBox {
  867. display: flex;
  868. .templateListClass {
  869. margin-right:20px;
  870. .templateListClassItem {
  871. width: 120px;
  872. height: 38px;
  873. text-align: center;
  874. line-height: 38px;
  875. border:1px solid #E3E8FA;
  876. background: #F5F7FB;
  877. margin-bottom: 10px;
  878. border-radius: 8px;
  879. cursor: pointer;
  880. }
  881. }
  882. .templateListBox {
  883. box-sizing: border-box;
  884. width: 100%;
  885. display:flex;
  886. flex-wrap:wrap;
  887. .templateList {
  888. margin-right:10px;
  889. text-align: center;
  890. font-size:12px;
  891. margin-bottom: 10px;
  892. border:1px solid #fff;
  893. padding: 5px;
  894. .templateImg {
  895. width: 129px;
  896. height:157px;
  897. border-radius: 8px;
  898. cursor: pointer;
  899. }
  900. }
  901. }
  902. }
  903. //1.1 模板分页
  904. .pageNumBox {
  905. text-align: center;
  906. padding-top:20px;
  907. }
  908. .webSiteTemplateName {
  909. margin-left: 10px;
  910. line-height: 36px;
  911. }
  912. //1.2 模板缩略图
  913. .webSiteTemplateImg {
  914. width: 140px;
  915. height: 140px;
  916. cursor: pointer;
  917. display: flex;
  918. align-items: center;
  919. justify-content: center;
  920. border-radius: 12px;
  921. border: 1px solid #E1E2E9;
  922. .selectWebSiteTemplateImg {
  923. width: 140px;
  924. height: 140px;
  925. border-radius: 12px;
  926. display: block;
  927. cursor: pointer;
  928. }
  929. .webSiteTemplateText {
  930. color: #5570F1;
  931. height: 36px;
  932. line-height: 36px;
  933. text-align: center;
  934. }
  935. img {
  936. display: block;
  937. }
  938. }
  939. /*表单样式 end------------------------------------------------------------>*/
  940. //执行v-deep穿透scope选择器 start------------------------------------------------------------>*/
  941. ::v-deep .custom-form-item > .el-form-item__label {
  942. line-height: 140px !important;
  943. }
  944. ::v-deep .custom-textarea .el-textarea__inner {
  945. resize: none; /* 禁止用户拖拽调整大小 */
  946. }
  947. ::v-deep .custom-align-right .el-form-item__label {
  948. text-align: right; /* 设置标签文字右对齐 */
  949. }
  950. //执行v-deep穿透scope选择器 end------------------------------------------------------------>*/
  951. </style>