creatNews.vue 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  1. <template>
  2. <div class="mainBox">
  3. <div class="layerBox">
  4. <tableTitle :name="tableDivTitle" />
  5. <el-form :model="form" ref="form" :rules="formRules" label-position="left" label-width="120px">
  6. <div class="formDiv">
  7. <el-form-item label="资讯题目:" prop="title" class="custom-align-right">
  8. <el-input v-model="form.title" autocomplete="off" placeholder="请输入资讯标题"></el-input>
  9. <!-- <el-checkbox v-model="form.islink">是否使用外链</el-checkbox> -->
  10. <el-checkbox v-model="form.islink" v-if="creatNews_user_type == 10000">是否使用外链</el-checkbox>
  11. </el-form-item>
  12. <div v-if="form.islink == true">
  13. <el-form-item label="站点名称:" prop="web_site_id" class="custom-align-right">
  14. <el-cascader :key="parentKey" v-model="form.web_site_id" placeholder="请选择站点名称" popper-class="my_cascader"
  15. :options="creatNews_nav_pool_arr" @change="creatNews_nav_pool_change_fun(form.web_site_id)" filterable
  16. clearable></el-cascader>
  17. </el-form-item>
  18. <el-form-item label="栏目名称:" prop="cat_arr_id" class="custom-align-right">
  19. <el-cascader :key="parentKey_2" v-model="form.cat_arr_id" placeholder="请选择要绑定的栏目名称" :props="parentData_2"
  20. popper-class="my_cascader" filterable clearable></el-cascader>
  21. </el-form-item>
  22. <el-form-item label="外链地址:" prop="linkurl" class="custom-align-right">
  23. <el-input v-model="form.linkurl" autocomplete="off" placeholder="请输入外链地址"></el-input>
  24. </el-form-item>
  25. <el-form-item label="作者:" prop="author" class="custom-align-right">
  26. <el-input v-model="form.author" autocomplete="off" placeholder="请输入作者"></el-input>
  27. </el-form-item>
  28. </div>
  29. <div v-if="form.islink == false">
  30. <div v-if="creatNews_user_type != 10000">
  31. <el-form-item label="栏目名称:" prop="cat_arr_id" class="custom-align-right">
  32. <el-cascader :key="parentKey" v-model="form.cat_arr_id" placeholder="请选择要绑定的栏目名称" :props="parentData"
  33. popper-class="my_cascader" style="height: 100%;" filterable clearable>
  34. </el-cascader>
  35. </el-form-item>
  36. </div>
  37. <div>
  38. <div v-if="creatNews_user_type == 10000">
  39. <el-form-item label="站点名称:" prop="web_site_id" class="custom-align-right">
  40. <el-cascader :key="parentKey" v-model="form.web_site_id" placeholder="请选择站点名称"
  41. popper-class="my_cascader" :options="creatNews_nav_pool_arr"
  42. @change="creatNews_nav_pool_change_fun(form.web_site_id)" filterable clearable></el-cascader>
  43. </el-form-item>
  44. <el-form-item label="栏目名称:" prop="cat_arr_id" class="custom-align-right">
  45. <el-cascader :key="parentKey_2" v-model="form.cat_arr_id" placeholder="请选择要绑定的栏目名称"
  46. popper-class="my_cascader" style="height: 100%;" :props="parentData_2" filterable clearable>
  47. </el-cascader>
  48. </el-form-item>
  49. </div>
  50. <el-form-item label="行政区划:" class="custom-align-right">
  51. <CityCascader v-model="form.city_arr_id" @update-city-id="update_city_arr_id"></CityCascader>
  52. </el-form-item>
  53. <el-form-item label="行政职能:" class="custom-align-right">
  54. <el-cascader :key="searchDepartmentKey" v-model="form.department_arr_id" placeholder="请选择行政职能"
  55. popper-class="my_cascader" :props="searchDepartmentData" filterable clearable></el-cascader>
  56. </el-form-item>
  57. <div v-if="creatNews_user_type == 10000">
  58. <el-form-item label="推荐等级:" class="custom-align-right">
  59. <el-select v-model="form.level" multiple clearable placeholder="请选择推荐等级.." @change="levelChange">
  60. <el-option label="头条" :value="1"></el-option>
  61. <el-option label="轮播图" :value="2"></el-option>
  62. <el-option label="今日热点" :value="6"></el-option>
  63. <el-option label="规章制度" :value="8"></el-option>
  64. </el-select>
  65. </el-form-item>
  66. </div>
  67. <el-form-item label="缩略图:" class="custom-align-right" prop="">
  68. <div class="uploaderBox" @mouseenter="hovering = true" mouseleave="hovering = false">
  69. <el-upload class="avatar-uploader" action="#" :show-file-list="false"
  70. :before-upload="beforeAvatarUpload">
  71. <!-- 预览图片 -->
  72. <img v-if="imgUrl" :src="imgUrl" class="avatar">
  73. <div v-else class="chooseImgDiv">
  74. <div>
  75. <img src="@/assets/public/upload/noImage.png">
  76. <div>选择图片</div>
  77. </div>
  78. </div>
  79. </el-upload>
  80. <input type="hidden" v-model="form.imgurl">
  81. <span class="photo_tips">推荐图片长宽比例为 16:9,大小不能超过 500 K。</span>
  82. <div v-if="hovering && imgUrl" class="delete-button" @click="handleDelete">
  83. <i class="el-icon-delete"></i>
  84. </div>
  85. </div>
  86. </el-form-item>
  87. <el-form-item label="资讯关键词:" prop="" class="custom-align-right">
  88. <template #label>
  89. <span class="askBox">
  90. 资讯关键词:
  91. <el-tooltip class="item" effect="dark" content="资讯关键词,如:三农市场网、全国三农、信息一体化。" placement="top">
  92. <i class="el-icon-question"></i>
  93. </el-tooltip>
  94. </span>
  95. </template>
  96. <tagInput :initialTags="tags" @tags-updated="updateTags"></tagInput>
  97. </el-form-item>
  98. <el-form-item label="资讯描述:" prop="" class="custom-align-right">
  99. <template #label>
  100. <span class="askBox">
  101. 资讯描述:
  102. <el-tooltip class="item" effect="dark" content="资讯描述,如:中国三农市场网创建以来,社会效益和会员经济效益贡献。" placement="top">
  103. <i class="el-icon-question"></i>
  104. </el-tooltip>
  105. </span>
  106. </template>
  107. <el-input type="textarea" v-model="form.introduce" class="custom-textarea"
  108. placeholder="请输入资讯描述"></el-input>
  109. </el-form-item>
  110. <el-form-item label="作者:" prop="author" class="custom-align-right">
  111. <el-input v-model="form.author" autocomplete="off" placeholder="请输入作者"></el-input>
  112. </el-form-item>
  113. <el-form-item label="浏览量:" v-if="creatNews_user_type == 10000" class="custom-align-right">
  114. <el-input v-model="form.hits" autocomplete="off" placeholder="请输入浏览量"></el-input>
  115. </el-form-item>
  116. <el-form-item label="是否为原创:" prop="is_original" class="custom-align-right">
  117. <el-radio-group v-model="form.is_original" @change="changeIsOriginal">
  118. <el-radio :label="1">是</el-radio>
  119. <el-radio :label="0">否</el-radio>
  120. </el-radio-group>
  121. </el-form-item>
  122. <div v-if="form.is_original == 0">
  123. <el-form-item label="来源名称:" prop="copyfrom" class="custom-align-right">
  124. <el-input v-model="form.copyfrom" autocomplete="off" placeholder="请输入来源名称"></el-input>
  125. </el-form-item>
  126. <el-form-item label="来源链接:" prop="fromurl" class="custom-align-right">
  127. <el-input v-model="form.fromurl" autocomplete="off" placeholder="请输入来源链接"></el-input>
  128. </el-form-item>
  129. <div class="disclaimerBox">
  130. <div class="disclaimerTitle">
  131. <img src="@/assets/public/check.png" />同意《免责声明》:
  132. </div>
  133. <div class="disclaimerText">
  134. 本文来源于网络转载,仅供学习交流使用,不构成商业目的。版权归原作者所有,如涉及作品内容、版权和其他问题,请在30日内与本站联系,我们将在第一时间处理。</div>
  135. </div>
  136. </div>
  137. <div v-if="form.is_original == 1">
  138. <el-form-item label="来源名称:" prop="copyfrom" class="custom-align-right">
  139. <el-input v-model="form.copyfrom" autocomplete="off" placeholder="请输入来源名称"
  140. disabled="disabled"></el-input>
  141. </el-form-item>
  142. </div>
  143. <el-form-item label="资讯内容:" prop="content" class="custom-align-right">
  144. <myEditor ref="myEditor" v-model="form.content"></myEditor>
  145. </el-form-item>
  146. <el-form-item label="是否开启投票:" prop="is_survey" class="custom-align-right">
  147. <el-radio-group v-model="form.is_survey">
  148. <el-radio :label="1">是</el-radio>
  149. <el-radio :label="0">否</el-radio>
  150. </el-radio-group>
  151. </el-form-item>
  152. <div v-if="form.is_survey == 1">
  153. <el-form-item label="问卷标题:" prop="survey_name" class="custom-align-right">
  154. <el-input v-model="form.survey_name" autocomplete="off" placeholder="请输入问卷标题"></el-input>
  155. </el-form-item>
  156. <el-form-item label="选项:" prop="survey_type" class="custom-align-right">
  157. <el-radio-group v-model="form.survey_type">
  158. <el-radio :label="0">单选</el-radio>
  159. <el-radio :label="1">多选</el-radio>
  160. </el-radio-group>
  161. </el-form-item>
  162. <el-form-item label="" class="custom-align-right">
  163. <div v-for="(input, index) in inputList" :key="index">
  164. <div class="formLabelFloatBox">
  165. <el-input autocomplete="off" v-model="input.value" maxlength="150" :label-width="formLabelWidth"
  166. placeholder="">
  167. <template slot="prepend">{{ index + 1 }}</template>
  168. </el-input>
  169. <el-button type="info" icon="el-icon-plus" circle size="mini" @click="addInput(index)"
  170. class="formLabeladdIcon"></el-button>
  171. <el-button type="info" icon="el-icon-delete" circle size="mini" @click="deleteInput(index)"
  172. class="formLabelDelIcon"></el-button>
  173. </div>
  174. </div>
  175. </el-form-item>
  176. <el-form-item label="" class="custom-align-right">
  177. <el-checkbox v-model="checked">允许用户自己填写</el-checkbox>
  178. </el-form-item>
  179. </div>
  180. <el-form-item label="手动推荐:" prop="commend_id" class="custom-align-right">
  181. <el-select v-model="form.commend_id" placeholder="请选择手动推荐名称" multiple filterable clearable remote
  182. :remote-method="remoteMethod" :loading="loading">
  183. <el-option v-for="item in commend_article" :key="item.id" :label="item.title"
  184. :value="item.id"></el-option>
  185. </el-select>
  186. </el-form-item>
  187. <el-form-item label="" prop="commend_id" class="custom-align-right">
  188. <draggable v-model="form.commend_id" @end="onDragEnd">
  189. <el-tag :key="item.id" v-for="item in form.commend_id" closable :disable-transitions="false"
  190. @close="handleClose(item)"> {{ item }}
  191. </el-tag>
  192. </draggable>
  193. </el-form-item>
  194. <el-form-item label="创建时间:" class="custom-align-right" v-if="created_at">
  195. <el-input v-model="created_at" autocomplete="off" disabled></el-input>
  196. </el-form-item>
  197. <el-form-item label="发布时间:" class="custom-align-right">
  198. <el-date-picker v-model="form.publiced_at" type="date" placeholder="请选择发布时间"
  199. :picker-options="pickerOptions" value-format="yyyy-MM-dd">
  200. </el-date-picker>
  201. </el-form-item>
  202. <el-form-item label="附件:" class="custom-align-right" prop="" >
  203. <div v-if="fjUrl " class="chooseImgDiv1">
  204. <div> {{ this.fjUrl }}
  205. <div></div>
  206. </div>
  207. </div>
  208. <div class="uploaderBox" @mouseenter="hovering = true" mouseleave="hovering = false">
  209. <el-upload class="avatar-uploader" action="#" :show-file-list="false" :before-upload="beforeAvatarUpload1">
  210. <!-- 预览图片 -->
  211. <div v-if="fjUrl" class="notchooseImgDiv">
  212. <img src="http://192.168.1.234:19000/pre/image/png/20260107/1767778011971130.png">
  213. <div class="notchooseImgDivText">已上传文档</div>
  214. </div>
  215. <div v-else class="chooseImgDiv">
  216. <div>
  217. <img src="@/assets/public/upload/noImage.png">
  218. <div>选择文档</div>
  219. </div>
  220. </div>
  221. </el-upload>
  222. <input type="hidden" v-model="form.fujian">
  223. <span class="photo_tips">支持文件形式pdf,word,jpg,zip文件最大50M。</span>
  224. <div v-if="hovering && form.fujian" class="delete-button" @click="handleDelete1">
  225. <i class="el-icon-delete"></i>
  226. </div>
  227. </div>
  228. </el-form-item>
  229. </div>
  230. </div>
  231. </div>
  232. </el-form>
  233. </div>
  234. <div class="bottomBtnBox">
  235. <el-button type="info" @click="returnPage">返回</el-button>
  236. <el-button type="primary" @click="editToServe" v-if="editStatus == true">确定</el-button>
  237. <el-button type="primary" @click="addToServe" v-else>发布资讯</el-button>
  238. </div>
  239. </div>
  240. </template>
  241. <script>
  242. import { getWebSiteId, getUseType } from '@/utils/auth'
  243. //表格标题
  244. import tableTitle from './components/tableTitle.vue';
  245. //引入tag标签组件
  246. import tagInput from '../../components/InputTag/index.vue';
  247. //引入公用样式
  248. import '@/styles/global.less';
  249. //城市级联选择器
  250. import CityCascader from './components/CityCascader';
  251. //引入富文本编辑器
  252. import myEditor from '../../components/edit/myEditor.vue';
  253. //引入拖拽组件
  254. import draggable from 'vuedraggable';
  255. export default {
  256. components: {
  257. tableTitle,
  258. CityCascader,
  259. tagInput,
  260. myEditor,
  261. draggable
  262. },
  263. data() {
  264. //0.全局操作 start ------------------------------------------------------------>
  265. //表单验证
  266. const validateEmpty = (rule, value, callback) => {
  267. if (value == '') {
  268. callback(new Error('该项不能为空!'))
  269. } else {
  270. callback()
  271. }
  272. }
  273. const validateArray = (rule, value, callback) => {
  274. if (value.length == 0) {
  275. callback(new Error('该项不能为空!'))
  276. } else {
  277. callback()
  278. }
  279. }
  280. const validateRadio = (rule, value, callback) => {
  281. if (value != '1' || value != '0') {
  282. callback()
  283. } else {
  284. callback()
  285. }
  286. }
  287. const validateZero = (rule, value, callback) => {
  288. if (value == 0 || value == '' || value == "0") {
  289. callback(new Error('该项不能为空!'))
  290. } else {
  291. callback()
  292. }
  293. }
  294. let self = this;
  295. //0.全局操作 end ------------------------------------------------------------>
  296. return {
  297. pickerOptions: {
  298. disabledDate(time) {
  299. return time.getTime() > Date.now();
  300. }
  301. },
  302. website_id: "",
  303. loading: false,
  304. logoUrl: '',
  305. hovering: false, // 鼠标悬浮状态 悬浮时显示删除
  306. tags: [],//标签数组
  307. websiteid: getWebSiteId() ? getWebSiteId() : 2,
  308. creatNews_pid_num: "0",//请求子导航用的pid
  309. creatNews_nav_pool_arr: [],//
  310. creatNews_add_nav_pool_arr: [],//
  311. creatNews_son_website_id_num: "",
  312. checked: false,
  313. formLabelWidth: '80px',//表单的长度
  314. //1.表单项 start ------------------------------------------------------------>
  315. editStatus: false,
  316. tableDivTitle: "添加资讯",
  317. disclaimer: true,//免责声明
  318. //提交表单
  319. creatNews_user_type: 0,//判断用户类型'
  320. created_at: "",//创建时间
  321. commend_article: [],//手动推荐
  322. form: {
  323. user_type: "??",//判断用户类型'
  324. cat_arr_id: [],//导航池名称
  325. nav_add_pool_id: [],//导航池子级
  326. city_arr_id: [],//行政区划
  327. city_id: "",//区划最后一个数字
  328. department_arr_id: [],//行政职能部门
  329. department_id: "",//部门最后一个数字
  330. //1.1使用了外链
  331. title: '',//资讯标题
  332. islink: 0,//是否使用外链 0非 1是
  333. linkurl: "",//外链地址
  334. //1.2没有使用外链
  335. level: "",//推荐等级
  336. imgurl: "",//缩略图
  337. keyword: "",//关键词
  338. introduce: "",//描述
  339. content: "",//内容
  340. author: "",//作者
  341. hits: "",//浏览量
  342. is_original: 1,//是否为原创 0非 1是
  343. copyfrom: "本网",//来源名称
  344. fromurl: "",//来源地址
  345. status: 0,//状态 0待发布 1已发布 404已删除 如果是普通用户,这里始终为0
  346. web_site_id: 0,
  347. is_survey: 0,//调查问卷:0:否;1:是;
  348. survey_name: "",//问卷名称
  349. suvey_array: "",//选项名称集合
  350. survey_type: 0, //0:单选 1:复选
  351. commend_id: [],//手动推荐
  352. publiced_at: null,//发布时间
  353. fujian: "",//附件
  354. },
  355. //1.2 表单验证规则
  356. formRules: {
  357. //导航池名称不能为空
  358. web_site_id: [{ required: true, trigger: 'blur', validator: validateZero }],
  359. //资讯名称不能为空
  360. title: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  361. //如果使用了外链,外链地址不能为空
  362. linkurl: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  363. //导航池名称不能为空
  364. cat_arr_id: [{ required: true, trigger: 'blur', validator: validateArray }],
  365. //推荐等级不能为空
  366. //level:[{required:true,trigger:'blur',validator:validateEmpty}],
  367. //关键词不能为空
  368. // keyword: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  369. //描述不能为空
  370. // introduce: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  371. //行政区划
  372. // city_arr_id: [{ required: true, trigger: 'blur', validator: validateArray }],
  373. //行政职能
  374. department_arr_id: [{ required: true, trigger: 'blur', validator: validateArray }],
  375. //内容不能为空
  376. content: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  377. //作者不能为空
  378. author: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  379. //是否原创不能为空
  380. is_original: [{ required: true, trigger: 'blur', validator: validateRadio }],
  381. //来源名称和地址不能为空
  382. copyfrom: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  383. fromurl: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  384. //缩略图不能为空
  385. imgUrl: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  386. level: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  387. //是否开启投票
  388. is_survey: [{ required: true, trigger: 'blur', validator: validateRadio }],
  389. //问卷标题
  390. survey_name: [{ required: true, trigger: 'blur', validator: validateEmpty }],
  391. //选项
  392. survey_type: [{ required: true, trigger: 'blur', validator: validateRadio }],
  393. },
  394. //1.4图片上传
  395. imgUrl: "",//在页面上显示缩略图
  396. fjUrl: "",//在页面上显示附件
  397. //获取父级导航池
  398. parentKey: 0,//获取父级导航
  399. parentData: {
  400. checkStrictly: true,
  401. lazy: true,
  402. async lazyLoad(node, resolve) {
  403. const { level, data } = node;
  404. if (data && data.children && data.children.length !== 0) {
  405. return resolve(node)
  406. }
  407. let parentId;
  408. parentId = level == 0 ? 0 : data.value;
  409. let parames = {
  410. 'type': 1,
  411. 'website_id': getWebSiteId(),
  412. 'pid': parentId
  413. }
  414. self.$store.dispatch('pool/get_creatNews_nav_son_actions', parames).then(res => {
  415. if (res.data) {
  416. const nodes = res.data.map(item => ({
  417. value: item.category_id,
  418. label: item.alias,
  419. leaf: level >= 3,
  420. children: [],
  421. disabled: item.type != 1
  422. }))
  423. resolve(nodes)
  424. }
  425. })
  426. }
  427. },
  428. parentKey_2: 0,//获取父级导航
  429. parentData_2: {
  430. checkStrictly: true,
  431. lazy: true,
  432. async lazyLoad(node, resolve) {
  433. const { level, data } = node;
  434. if (data && data.children && data.children.length !== 0) {
  435. return resolve(node)
  436. }
  437. let parentId;
  438. if (self.ifwebsitId == true) {
  439. console.log("网站选择已经改变!")
  440. parentId = 0;
  441. self.ifwebsitId = false;
  442. self.cat_arr_id = [];
  443. } else {
  444. parentId = level == 0 ? 0 : data.value;
  445. self.ifwebsitId = false;
  446. }
  447. let parames = {
  448. 'type': 1,
  449. 'website_id': self.form.web_site_id,
  450. 'pid': parentId
  451. }
  452. self.$store.dispatch('pool/get_creatNews_nav_son_actions', parames).then(res => {
  453. if (res.data) {
  454. const nodes = res.data.map(item => ({
  455. value: item.category_id,
  456. label: item.alias,
  457. leaf: level >= 3,
  458. children: [],
  459. disabled: item.type != 1
  460. }))
  461. resolve(nodes)
  462. }
  463. })
  464. }
  465. },
  466. //行政职能部门
  467. searchDepartmentKey: 0, //列表缓存key
  468. searchDepartmentData: {
  469. checkStrictly: true,
  470. lazy: true,
  471. async lazyLoad(node, resolve) {
  472. const { level, data } = node;
  473. if (data && data.children && data.children.length !== 0) {
  474. return resolve(node)
  475. }
  476. console.log(level)
  477. let parentId = level == 0 ? 0 : data.value
  478. let parames = {
  479. 'pid': parentId
  480. }
  481. self.$store.dispatch('pool/getDepartment', parames).then(res => {
  482. if (res.data) {
  483. const nodes = res.data.map(item => ({
  484. value: item.id,
  485. label: item.name,
  486. leaf: level >= 3,
  487. children: []
  488. }))
  489. resolve(nodes)
  490. }
  491. })
  492. }
  493. },
  494. inputList: [
  495. { value: '' }
  496. ]
  497. //表单项 end ------------------------------------------------------------>
  498. };
  499. },
  500. watch: {
  501. '$route'(to, from) {
  502. console.log(from, '---------------------------------------');
  503. // 监听路由参数中的 id 变化,若变化则更新页面状态并获取数据
  504. if (to.query.id) {
  505. this.getMainData();
  506. }
  507. },
  508. // 监听路由参数中的 id 变化,若变化则更新页面状态并获取数据
  509. // '$route.query.id': function (newVal, oldVal) {
  510. // console.log('当前 id:', newVal, '旧的 id:', oldVal);
  511. // if (newVal) {
  512. // this.editStatus = true;
  513. // this.tableDivTitle = "编辑资讯";
  514. // // // 调用方法名保持大小写一致
  515. // this.getMainData();
  516. // } else {
  517. // this.editStatus = false;
  518. // this.tableDivTitle = "添加资讯";
  519. // }
  520. // }
  521. },
  522. methods: {
  523. //1.提交表单 start ------------------------------------------------------------>
  524. //1.1 直接上传图片
  525. beforeAvatarUpload(file) {
  526. const isJPG = file.type === 'image/jpeg';
  527. const isPNG = file.type === 'image/png';
  528. const isLt2M = file.size / 1024 / 1024 < 2;
  529. if (!isJPG && !isPNG) {
  530. this.$message.error('上传缩略图只能是 JPG 或 PNG 格式!');
  531. return false;
  532. }
  533. if (!isLt2M) {
  534. this.$message.error('上传缩略图大小不能超过 2MB!');
  535. return false;
  536. }
  537. const formData = new FormData();
  538. formData.append('file', file);
  539. this.$store.dispatch('pool/uploadFile', formData).then(res => {
  540. this.imgUrl = res.data.imgUrl;//显示缩略图
  541. this.form.imgurl = res.data.imgUrl;//提供表单地址
  542. console.log(res.data.imgUrl)
  543. }).catch(() => {
  544. this.$message({
  545. type: 'info',
  546. message: '网络错误,请重试!'
  547. });
  548. })
  549. // 阻止默认的上传行为
  550. return false;
  551. },
  552. //1.1.1 直接上传文件
  553. beforeAvatarUpload1(file) {
  554. const isWord = file.type ==='application/msword' || 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' || 'application/vnd.ms-word' || 'doc';
  555. const isPdf = file.type === 'application/pdf' || file.type === 'application/x-pdf' || file.type === 'application/acrobat' || file.type === 'pdf' || file.type === 'text/x-pdf' || file.type === 'application/x-download' || file.type === 'application/octet-stream';
  556. const isZip = file.type === 'application/zip' || file.type === 'application/x-zip-compressed' || file.type === 'application/x-zip' || file.type === 'application/x-compress' || file.type === 'application/x-compressed' || file.type === 'multipart/x-zip' || file.type === 'multipart/x-zip-compressed' || file.type === 'zip';
  557. const isLt50M = file.size / 1024 / 1024 < 50;
  558. console.log('文件类型',file.type)
  559. if (!isWord && !isExcel && !isPdf && !isZip) {
  560. this.$message.error('上传文件只能是 Word/Excel/Pdf/压缩包 格式!');
  561. return false;
  562. }
  563. if (!isLt50M) {
  564. this.$message.error('上传文件大小不能超过 50MB!');
  565. return false;
  566. }
  567. const formData = new FormData();
  568. formData.append('file', file);
  569. this.$store.dispatch('pool/uploadFile', formData).then(res => {
  570. this.fjUrl = res.data.imgUrl;//显示缩略图
  571. this.form.fujian = res.data.imgUrl;//提供表单地址
  572. console.log(res.data.imgUrl)
  573. }).catch(() => {
  574. this.$message({
  575. type: 'info',
  576. message: '网络错误,请重试!'
  577. });
  578. })
  579. // 阻止默认的上传行为
  580. return false;
  581. },
  582. //1.2 提交表单
  583. addToServe() {
  584. //判断是否为外链
  585. if (this.form.islink == false) {
  586. if (this.form.is_survey == 1) {
  587. const hasEmptyInput = this.inputList.some(input => input.value === '');
  588. if (hasEmptyInput) {
  589. // 如果有输入框为空,弹出提示信息
  590. this.$message.error('请确保所有输入框都有内容');
  591. return;
  592. }
  593. const inputLists = this.inputList.map(input => input.value);
  594. const allowList = [this.checked ? 1 : 0, ""];
  595. if (this.checked) {
  596. inputLists.push(allowList);
  597. }
  598. if (inputLists.length < 2) {
  599. this.$message.error('投票选项不少于2条');
  600. return;
  601. }
  602. this.form.suvey_array = JSON.stringify(inputLists);
  603. }
  604. }
  605. if (this.form.islink == true) {
  606. this.form.islink = 1;
  607. this.cleatForm(1)
  608. } else {
  609. this.form.islink = 0;
  610. }
  611. //取出行政职能和行政区划数组的最后一个数字
  612. if (this.form.department_arr_id == "[]" || this.form.department_arr_id == null) {
  613. this.form.department_arr_id = '[]'
  614. this.form.department_id = 0;
  615. } else {
  616. if (JSON.parse(this.form.department_arr_id.length == 0)) {
  617. this.form.department_id = 0;
  618. } else {
  619. this.form.department_id = this.form.department_arr_id[this.form.department_arr_id.length - 1];
  620. }
  621. this.form.department_arr_id = JSON.stringify(this.form.department_arr_id);
  622. }
  623. if (this.form.city_arr_id == "[]" || this.form.city_arr_id == null) {
  624. this.form.city_arr_id = '[]'
  625. this.form.city_id = 0;
  626. } else {
  627. if (JSON.parse(this.form.city_arr_id.length == 0)) {
  628. this.form.city_id = 0;
  629. } else {
  630. this.form.city_id = this.form.city_arr_id[this.form.city_arr_id.length - 1];
  631. }
  632. this.form.city_arr_id = JSON.stringify(this.form.city_arr_id);
  633. }
  634. //判断用户身份
  635. if (this.creatNews_user_type == 10000) {
  636. console.log("用户身份为管理员,无需审核直接发布!")
  637. this.form.status = 1;
  638. this.form.web_site_id = this.form.web_site_id ? this.form.web_site_id : this.websiteid;
  639. } else {
  640. console.log("用户身份为其他用户,提交到审核!")
  641. this.form.status = 0;
  642. this.form.web_site_id = this.websiteid;
  643. //如果是普通用户 推荐等级设置为0
  644. this.form.level = "[0]";
  645. }
  646. //先进行验证
  647. // console.log( "this.form==", this.form);
  648. this.$refs.form.validate(valid => {
  649. if (valid) {
  650. //如果推荐等级为空,则设置为0
  651. if (this.form.level == "" || this.form.level == "[0]") {
  652. this.form.level = "[0]";
  653. } else {
  654. this.form.level = JSON.stringify(this.form.level);
  655. }
  656. //console.log(this.form)
  657. const formData = { ...this.form };
  658. if (formData.commend_id != undefined && formData.commend_id.length > 0) {
  659. formData.commend_id = JSON.stringify(formData.commend_id); // 提取推荐ID
  660. }
  661. if (formData.commend_id.length == 0) {
  662. formData.commend_id = '[]';
  663. }
  664. this.$store.dispatch('news/addArticle', formData).then(res => {//
  665. if (res.code == 200) {
  666. console.log("资讯发布成功!200")
  667. //汇报结果
  668. if (this.creatNews_user_type == 10000) {
  669. this.$message({
  670. type: 'success',
  671. message: '已成功添加资讯!'
  672. });
  673. this.cleatForm(2);
  674. //返回列表页
  675. this.returnPage()
  676. } else {
  677. this.$message({
  678. type: 'success',
  679. message: '待管理员审核!'
  680. });
  681. this.cleatForm(2);
  682. //返回列表页
  683. this.returnPage()
  684. }
  685. } else {
  686. this.$message({
  687. type: 'error',
  688. message: res.message
  689. });
  690. }
  691. }).catch(() => {
  692. this.$message({
  693. type: 'info',
  694. message: '网络错误,请重试!'
  695. });
  696. })
  697. }
  698. })
  699. },
  700. //1.3 清理表单
  701. cleatForm(type) {
  702. if (type == 1) {
  703. //使用了外链,进行部分表单清理
  704. //this.form.cat_arr_id = "";
  705. this.form.level = "";
  706. this.form.imgurl = "";
  707. this.form.keyword = "";
  708. this.form.introduce = "";
  709. this.form.content = "";
  710. //this.form.author = "";
  711. this.form.hits = "";
  712. this.form.is_original = "";
  713. this.form.copyfrom = "";
  714. this.form.fromurl = "";
  715. this.form.status = 0;
  716. }
  717. if (type == 2) {
  718. //完全清理表单
  719. this.form.title = "";
  720. this.form.islink = "";
  721. this.form.linkurl = "";
  722. this.form.cat_arr_id = "";
  723. this.form.level = "";
  724. this.form.imgurl = "";
  725. this.form.keyword = "";
  726. this.form.introduce = "";
  727. this.form.content = "";
  728. this.form.author = "";
  729. this.form.hits = "";
  730. this.form.is_original = "";
  731. this.form.copyfrom = "";
  732. this.form.fromurl = "";
  733. this.form.status = 0;
  734. this.form.fujian = "";//清空附件 URL
  735. }
  736. },
  737. //1.4更新详细地址
  738. update_city_arr_id(value) {
  739. console.log("行政区划ID已更新:", value);
  740. this.form.city_arr_id = value;
  741. },
  742. //1.5 删除图片
  743. handleDelete() {
  744. // 删除图片
  745. this.imgUrl = ''; // 清空图片 URL
  746. this.form.imgurl = ''; // 清空表单中的图片 URL
  747. },
  748. //1.5 删除附件
  749. handleDelete1() {
  750. // 删除附件
  751. this.fjUrl = ''; // 清空附件 URL
  752. this.form.fujian = ''; // 清空表单中的附件 URL
  753. },
  754. //提交表单 end ------------------------------------------------------------>
  755. //2.跳转操作 start ------------------------------------------------------------>
  756. returnPage() {
  757. if (this.$route.query.to == "examine") {
  758. this.$router.push({
  759. path: '/examine',
  760. });
  761. } else {
  762. this.$router.push({
  763. path: '/articleList',
  764. });
  765. }
  766. },
  767. //跳转操作 end ------------------------------------------------------------>
  768. //3.回显操作 ------------------------------------------------------------>
  769. //3.1回显数据
  770. getMainData() {
  771. let data = {
  772. id: this.$route.query.id
  773. };
  774. this.$store.dispatch('news/getArticleInfo', data).then(res => {
  775. this.form.title = res.data.title;
  776. this.fjUrl = res.data.fujian; // 回显附件 URL
  777. //判断是否使用了外链
  778. if (res.data.islink == 1) {
  779. this.form.islink = true;
  780. } else {
  781. this.form.islink = false;
  782. }
  783. //不是原创的时候显示来源
  784. if (res.data.is_original == 1) {
  785. this.form.is_original = 1;
  786. this.form.copyfrom = "本网";
  787. } else {
  788. this.form.is_original = 0;
  789. this.$nextTick(() => {
  790. this.form.is_original = 0;
  791. console.log('is_original:', this.form.is_original); // 确保值已更新
  792. });
  793. this.form.copyfrom = res.data.copyfrom;
  794. this.form.linkurl = res.data.linkurl;
  795. }
  796. //如果推荐等级为0 不再回显等级
  797. if (res.data.level == "[0]") {
  798. this.form.level = "";
  799. } else {
  800. const arr = JSON.parse(res.data.level);
  801. const elementToRemove = [0, 3, 4, 5];
  802. let newArr = arr.filter(item => !elementToRemove.includes(item));;
  803. this.form.level = newArr;
  804. }
  805. //回显站点名称
  806. //判断web_site_id是否为字符串,如果是转换为数字
  807. if (typeof res.data.web_site_id === 'string') {
  808. this.form.web_site_id = Number(res.data.web_site_id);
  809. } else {
  810. this.form.web_site_id = res.data.web_site_id//站点名称
  811. }
  812. this.created_at = res.data.created_at;
  813. this.form.cat_arr_id = Array.isArray(res.data.cat_arr_id) ? res.data.cat_arr_id : JSON.parse(res.data.cat_arr_id);
  814. console.log(this.form.cat_arr_id)
  815. //回显导航池 连同非管理员得一起刷新
  816. this.parentKey += 1; // 触发级联选择器重新加载
  817. this.loadCascaderPath(this.form.cat_arr_id); // 加载路径数据
  818. this.parentKey_2 += 1; // 触发级联选择器重新加载
  819. this.loadCascaderPath(this.form.cat_arr_id); // 加载路径数据
  820. //回显行政区划
  821. this.form.city_arr_id = JSON.parse(res.data.city_arr_id);
  822. //回显行政职能
  823. this.searchDepartmentKey += 1;
  824. this.form.department_arr_id = JSON.parse(res.data.department_arr_id);
  825. //回显其他数据
  826. this.form.imgurl = res.data.imgurl;
  827. this.imgUrl = res.data.imgurl;
  828. this.form.keyword = res.data.keyword;
  829. this.tags = res.data.keyword ? res.data.keyword.split(",") : [];
  830. this.form.introduce = res.data.introduce;
  831. //回显编辑器内容
  832. this.$nextTick(() => {
  833. this.form.content = res.data.content;
  834. });
  835. this.form.author = res.data.author;
  836. this.form.hits = res.data.hits;
  837. this.form.is_original = res.data.is_original;
  838. this.form.copyfrom = res.data.copyfrom;
  839. this.form.fromurl = res.data.fromurl;
  840. this.form.status = res.data.status;
  841. this.form.survey_name = res.data.survey_name;
  842. this.form.commend_id = JSON.parse(res.data.commend_id);
  843. this.form.fujian = res.data.fujian;
  844. if (res.data.is_survey == null) {
  845. this.form.is_survey = 0;
  846. } else {
  847. this.form.is_survey = res.data.is_survey;
  848. }
  849. this.form.survey_type = res.data.survey_type;
  850. this.inputList = [];
  851. if (res.data.survey_array.length > 0) {
  852. res.data.survey_array.forEach(item => {
  853. if (item.is_other == 0) {
  854. this.inputList.push({ "value": item.choice_name });
  855. } else {
  856. this.checked = true
  857. }
  858. });
  859. } else {
  860. this.inputList.push({ "value": "" });
  861. }
  862. this.form.publiced_at = res.data.publiced_at;
  863. console.log(this.inputList)
  864. })
  865. },
  866. async loadCascaderPath(path) {
  867. for (let i = 0; i < path.length; i++) {
  868. const parentId = path[i - 1] || 0; // 获取当前层级的父级ID
  869. const level = i; // 当前层级的索引
  870. await this.$store.dispatch('pool/categoryList', { pid: parentId })
  871. .then((res) => {
  872. const nodes = res.data.map(item => ({
  873. value: item.id,
  874. label: item.name,
  875. leaf: level >= 3, // 假设4层结构,设置叶子节点标记
  876. }));
  877. // 级联选择器加载数据
  878. if (level === path.length - 1) {
  879. this.form.cat_arr_id = path; // 确保最后一级路径正确设置
  880. this.parentKey += 1; // 强制刷新 cascader
  881. }
  882. });
  883. }
  884. },
  885. //1.3提交修改
  886. editToServe() {
  887. //不使用外联 验证投票逻辑
  888. if (this.form.islink == false) {
  889. if (this.form.is_survey == 1) {
  890. const hasEmptyInput = this.inputList.some(input => input.value === '');
  891. if (hasEmptyInput) {
  892. // 如果有输入框为空,弹出提示信息
  893. this.$message.error('请确保所有输入框都有内容');
  894. return;
  895. }
  896. const inputLists = this.inputList.map(input => input.value);
  897. const allowList = [this.checked ? 1 : 0, ""];
  898. if (this.checked) {
  899. inputLists.push(allowList);
  900. }
  901. if (inputLists.length < 2) {
  902. this.$message.error('投票选项不少于2条');
  903. return;
  904. }
  905. this.form.suvey_array = JSON.stringify(inputLists);
  906. }
  907. }
  908. console.log(this.form)
  909. if (this.form.islink == 1) {
  910. this.cleatForm(1)
  911. }
  912. //取出行政职能和行政区划数组的最后一个数字
  913. if (this.form.department_arr_id == "[]" || this.form.department_arr_id == null) {
  914. this.form.department_arr_id = '[]'
  915. this.form.department_id = 0;
  916. } else {
  917. if (JSON.parse(this.form.department_arr_id.length == 0)) {
  918. this.form.department_id = 0;
  919. } else {
  920. this.form.department_id = this.form.department_arr_id[this.form.department_arr_id.length - 1];
  921. }
  922. this.form.department_arr_id = JSON.stringify(this.form.department_arr_id);
  923. }
  924. if (this.form.city_arr_id == "[]" || this.form.city_arr_id == null) {
  925. this.form.city_arr_id = '[]'
  926. this.form.city_id = 0;
  927. } else {
  928. if (JSON.parse(this.form.city_arr_id.length == 0)) {
  929. this.form.city_id = 0;
  930. } else {
  931. this.form.city_id = this.form.city_arr_id[this.form.city_arr_id.length - 1];
  932. }
  933. this.form.city_arr_id = JSON.stringify(this.form.city_arr_id);
  934. }
  935. //将department_id和city_id转换为字符串
  936. // this.form.department_arr_id = JSON.stringify(this.form.department_arr_id);
  937. // this.form.city_arr_id = JSON.stringify(this.form.city_arr_id);
  938. //添加要修改的id
  939. this.form.id = this.editId;
  940. //判断用户身份
  941. if (this.creatNews_user_type == 10000) {
  942. if (this.$route.query.to == "examine") {
  943. //如果是管理员在编辑用户的新闻这里的status需要设置为0
  944. this.form.status = 0;
  945. } else {
  946. console.log("用户身份为管理员,无需审核直接发布!")
  947. this.form.status = 1;
  948. }
  949. } else {
  950. console.log("用户身份为其他用户,提交到审核!")
  951. this.form.status = 0;
  952. this.form.web_site_id = this.websiteid;
  953. }
  954. //先进行验证
  955. this.$refs.form.validate(valid => {
  956. if (valid) {
  957. //如果推荐等级为空,则设置为0
  958. if (this.form.level == "" || this.form.level == "[0]") {
  959. this.form.level = "[0]";
  960. } else {
  961. this.form.level = JSON.stringify(this.form.level);
  962. }
  963. const formData = { ...this.form };
  964. if (formData.commend_id != undefined && formData.commend_id.length > 0) {
  965. formData.commend_id = JSON.stringify(formData.commend_id); // 提取推荐ID
  966. }
  967. if (formData.commend_id.length == 0) {
  968. formData.commend_id = '[]';
  969. }
  970. //console.log(this.form)
  971. this.$store.dispatch('news/updateArticle', formData).then(res => {
  972. if (res.code != 200) {
  973. this.$message({
  974. type: 'error',
  975. message: res.message
  976. });
  977. } else {
  978. //汇报结果
  979. if (this.creatNews_user_type == 10000) {
  980. this.$message({
  981. type: 'success',
  982. message: '已成功编辑资讯!'
  983. });
  984. this.cleatForm(2);
  985. //返回列表页
  986. this.returnPage()
  987. } else {
  988. this.$message({
  989. type: 'success',
  990. message: '待管理员审核!'
  991. });
  992. this.cleatForm(2);
  993. //返回列表页
  994. this.returnPage()
  995. }
  996. }
  997. }).catch(() => {
  998. this.$message({
  999. type: 'info',
  1000. message: '网络错误,请重试!'
  1001. });
  1002. })
  1003. }
  1004. })
  1005. },
  1006. //1.4 修改是否原创
  1007. changeIsOriginal() {
  1008. if (this.form.is_original == 1) {
  1009. this.form.copyfrom = "本网";
  1010. } else {
  1011. this.form.copyfrom = "";
  1012. this.form.fromurl = "";
  1013. }
  1014. },
  1015. //跳转操作 end ------------------------------------------------------------>
  1016. //5.站点选择 曹国庆 start ------------------------------------------------------------>
  1017. get_creatNews_form_id_fun() {
  1018. //判断用户类型ajax
  1019. this.$store.dispatch('public/getInfo').then(res => {
  1020. // console.log("res======",res)
  1021. this.form.user_type = res.data.type_id;
  1022. }).catch(() => {
  1023. this.$message({
  1024. type: 'info',
  1025. message: '网络错误,请重试!'
  1026. });
  1027. })
  1028. },
  1029. get_creatNews_nav_pool_arr_fun() {//
  1030. this.$store.dispatch('pool/get_creatNews_nav_actions', { page: 1, pageSize: 666666 }).then(res => {
  1031. res.data.rows.forEach((per_obj) => {
  1032. let new_per = {
  1033. label: per_obj.website_name,
  1034. value: per_obj.id,
  1035. }
  1036. this.creatNews_nav_pool_arr.push(new_per)
  1037. })
  1038. }).catch(() => {
  1039. this.$message({
  1040. type: 'info',
  1041. message: '网络错误,请重试!'
  1042. });
  1043. })
  1044. },
  1045. creatNews_nav_pool_change_fun() {
  1046. //开启导航池级联选择器
  1047. this.ifwebsitId = true;
  1048. console.log(this.ifwebsitId)
  1049. // 导航池级
  1050. let that = this;
  1051. this.form.web_site_id = this.form.web_site_id[0]
  1052. that.parentKey_2 += 1;
  1053. this.$store.dispatch('pool/get_creatNews_nav_son_actions', { type: 1, pid: String(this.creatNews_pid_num), website_id: String(this.form.web_site_id) }).then(res => {
  1054. if (res.data.length == 0) {//没有导航池子级
  1055. // alert("没有导航池子级");
  1056. return
  1057. }
  1058. this.creatNews_add_nav_pool_arr = res.data;
  1059. this.creatNews_add_nav_pool_arr.forEach((per_obj) => {
  1060. per_obj.label = per_obj.name,
  1061. per_obj.value = per_obj.id,
  1062. this.creatNews_pid_num = per_obj.category_id
  1063. })
  1064. }).catch(() => {
  1065. this.$message({
  1066. type: 'info',
  1067. message: '网络错误,请重试!'
  1068. });
  1069. })
  1070. },
  1071. updateTags(newTags) {
  1072. // this.foem.seo_keywords = newTags;
  1073. this.tags = newTags;
  1074. this.form.keyword = newTags.join(',');
  1075. },
  1076. //推荐等级多选获取到的数据
  1077. levelChange(value) {
  1078. this.form.level = value;
  1079. },
  1080. getNews() {
  1081. this.$store.dispatch('news/getArticleCommend', {
  1082. 'page': 1,
  1083. 'pageSize': 20,
  1084. 'website_id': this.website_id,
  1085. }).then(res => {
  1086. console.log("手动推荐", res)
  1087. let data = [];
  1088. for (let item of res.data.rows) {
  1089. data.push(item)
  1090. }
  1091. this.commend_article = data;
  1092. }).catch(() => {
  1093. // this.$message({
  1094. // type: 'info',
  1095. // message: '网络错误,请重试!'
  1096. // });
  1097. })
  1098. },
  1099. // 远程搜索方法
  1100. remoteMethod(query) {
  1101. console.log("query", query);
  1102. const artical_params = {
  1103. page: 1,
  1104. pageSize: 20,
  1105. website_id: this.website_id,
  1106. }
  1107. if (query !== '') {
  1108. this.loading = true;
  1109. //如果全是数字,就id,其他就是搜title
  1110. let reg = /^[0-9]+$/;
  1111. let isNum = reg.test(query);
  1112. if (isNum) {
  1113. delete artical_params.title;
  1114. artical_params.id = query;
  1115. } else {
  1116. delete artical_params.id;
  1117. artical_params.title = String(query);
  1118. }
  1119. this.$store.dispatch('news/getArticleCommend', artical_params).then(res => {
  1120. this.loading = false;
  1121. let data = [];
  1122. for (let item of res.data.rows) {
  1123. data.push(item);
  1124. }
  1125. this.commend_article = data;
  1126. }).catch(() => {
  1127. this.loading = false;
  1128. // this.$message({
  1129. // type: 'info',
  1130. // message: '网络错误,请重试!'
  1131. // });
  1132. });
  1133. } else {
  1134. this.getNews()
  1135. }
  1136. },
  1137. //5.站点选择 曹国庆 end ------------------------------------------------------------>
  1138. //6.问卷 刘佳伟 start ------------------------------------------------------------>
  1139. addInput(index) {
  1140. // 在当前索引后插入一个新的输入框对象
  1141. if (this.inputList.length > 10) {
  1142. this.$message.warning('最多只能添加10个文本框');
  1143. return false;
  1144. }
  1145. this.inputList.splice(index + 1, 0, { value: '' });
  1146. },
  1147. deleteInput(index) {
  1148. if (this.inputList.length > 1) {
  1149. // 如果输入框数量大于 1,则删除当前索引对应的输入框对象
  1150. this.inputList.splice(index, 1);
  1151. } else {
  1152. this.$message.warning('至少保留一个输入框');
  1153. }
  1154. },
  1155. onDragEnd() {
  1156. // 处理拖拽结束事件(如果需要)
  1157. console.log('拖拽结束', this.commend_article);
  1158. },
  1159. handleClose(item) {
  1160. const index = this.form.commend_id.indexOf(item);
  1161. if (index > -1) {
  1162. this.form.commend_id.splice(index, 1);
  1163. }
  1164. },
  1165. //6.问卷 刘佳伟 end ------------------------------------------------------------>
  1166. },
  1167. mounted() {
  1168. console.log("mounted")
  1169. console.log(this.commend_article, '-------news-------');
  1170. this.creatNews_user_type = getUseType()
  1171. this.websiteid = getWebSiteId()
  1172. //1.获得站点标识
  1173. this.get_creatNews_form_id_fun()
  1174. this.get_creatNews_nav_pool_arr_fun()
  1175. //2.判断是新建还是回显
  1176. if (this.$route.query.id != undefined) {
  1177. this.editId = this.$route.query.id;
  1178. this.editStatus = true;
  1179. console.log("编辑新闻!")
  1180. this.getMainData();
  1181. } else {
  1182. this.editStatus = false;
  1183. console.log("添加新闻!")
  1184. }
  1185. },
  1186. watch: {
  1187. 'form.web_site_id': {
  1188. handler(newVal, oldVal) {
  1189. this.website_id = this.form.web_site_id ? newVal : this.websiteid
  1190. this.getNews()
  1191. console.log('websiteid', this.website_id);
  1192. },
  1193. immediate: true,
  1194. deep: true
  1195. }
  1196. },
  1197. };
  1198. </script>
  1199. <style scoped lang="less">
  1200. //执行v-deep穿透scope选择器 start------------------------------------------------------------>*/
  1201. ::v-deep .custom-form-item>.el-form-item__label {
  1202. line-height: 140px !important;
  1203. }
  1204. ::v-deep .custom-textarea .el-textarea__inner {
  1205. resize: none;
  1206. /* 禁止用户拖拽调整大小 */
  1207. }
  1208. ::v-deep .custom-align-right .el-form-item__label {
  1209. text-align: right;
  1210. /* 设置标签文字右对齐 */
  1211. }
  1212. ::v-deep .el-popper {
  1213. height: 500px;
  1214. }
  1215. ::v-deep .el-select {
  1216. width: 100%;
  1217. /* 禁止用户拖拽调整大小 */
  1218. }
  1219. ::v-deep .el-input-group__prepend {
  1220. color: black !important;
  1221. }
  1222. .formLabelFloatBox {
  1223. margin-bottom: 10px;
  1224. position: relative;
  1225. .formLabeladdIcon {
  1226. position: absolute;
  1227. right: 45px;
  1228. top: 5px;
  1229. width: 38px;
  1230. height: 24px;
  1231. }
  1232. .formLabelDelIcon {
  1233. position: absolute;
  1234. right: 5px;
  1235. top: 5px;
  1236. width: 38px;
  1237. height: 24px;
  1238. }
  1239. }
  1240. //该项不能为空几个字的位置
  1241. ::v-deep .el-form-item__error {
  1242. color: #ff4949;
  1243. font-size: 12px;
  1244. line-height: 1;
  1245. padding-top: 4px;
  1246. position: relative;
  1247. // top: 22%;
  1248. // left: 93%;
  1249. }
  1250. //输入框距离底部的距离
  1251. ::v-deep .el-form-item {
  1252. margin-bottom: 5px;
  1253. }
  1254. //图片提示文字样式
  1255. .photo_tips {
  1256. font-size: 12px;
  1257. color: #999;
  1258. }
  1259. .notchooseImgDiv img{
  1260. width: 120px;
  1261. height: 120px;
  1262. margin-left: 11px;
  1263. }
  1264. .notchooseImgDiv .notchooseImgDivText{
  1265. font-size: 14px;
  1266. margin-top: -25px;
  1267. }
  1268. // 执行v-deep穿透scope选择器 end------------------------------------------------------------></style>