editPage.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. <template>
  2. <div class="notice_changShang_edit">
  3. <form>
  4. <div class="Line Line1">
  5. <span>标题:</span>
  6. <input
  7. type="text"
  8. v-model="contentParam.title"
  9. @focus="hideTip"
  10. @blur="checkName"
  11. />
  12. <p v-show="tipFlag" style="margin-left: 88px; color: red">
  13. {{ tipText }}
  14. </p>
  15. </div>
  16. <div class="Line Line2">
  17. <span>类型:</span>
  18. <select>
  19. <option>重要通知</option>
  20. </select>
  21. </div>
  22. <div class="Line Line3">
  23. <span>区域:</span>
  24. <div class="areaBox">
  25. <div v-for="(item, index) in areaList" :key="index">
  26. <input
  27. type="checkbox"
  28. :value="item"
  29. v-model="contentParam.area"
  30. @click="clickCheckbox(index)"
  31. /><span>{{ item }}</span>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="Line Line4">
  36. <span>信息配置:</span>
  37. <div class="fuWenBen">
  38. <el-tiptap
  39. v-model="contentParam.content"
  40. :extensions="extensions"
  41. :charCounterCount="false"
  42. placeholder="Write something ..."
  43. >
  44. <!--charCounterCount 是否显示字数统计 -->
  45. </el-tiptap>
  46. </div>
  47. <div style="clear: both; display: block"></div>
  48. </div>
  49. <div class="uploadFile">
  50. <p class="title">附件:</p>
  51. <label for="fileInput" @change="getFileInfo($event)"
  52. >添加附件
  53. <input type="file" name="fileName" id="fileInput" multiple />
  54. </label>
  55. <div class="fileDes">
  56. <p v-for="(item, index) in contentParam.files" :key="index">
  57. {{ item.file_name || item.name }}
  58. <span class="deleteFile" @click="deleteFile(index, item)">×</span>
  59. </p>
  60. </div>
  61. </div>
  62. </form>
  63. <div class="operationStyle">
  64. <button @click="addNotice(contentParam.id)">保存</button>
  65. <button @click="backToPre()">返回</button>
  66. </div>
  67. <TipModal
  68. :tipFlag="tipModalFlag"
  69. :tipText="tipModalText"
  70. @close_tip_modal="closeTipModal"
  71. />
  72. <Loading v-if="uploading"></Loading>
  73. </div>
  74. </template>
  75. <script>
  76. import {
  77. // necessary extensions
  78. Doc,
  79. Paragraph,
  80. Text,
  81. Heading,
  82. History,
  83. Code,
  84. CodeBlock,
  85. Blockquote,
  86. BulletList,
  87. OrderedList,
  88. ListItem,
  89. TodoList,
  90. TodoItem,
  91. //Iframe,
  92. Table,
  93. TableHeader,
  94. TableRow,
  95. TableCell,
  96. TextAlign,
  97. LineHeight,
  98. Indent,
  99. HorizontalRule,
  100. HardBreak,
  101. TrailingNode,
  102. TextColor,
  103. TextHighlight,
  104. FormatClear,
  105. FontType,
  106. FontSize,
  107. // Preview,
  108. //Print,
  109. // SelectAll,
  110. Bold,
  111. //Underline,
  112. Italic,
  113. Strike,
  114. Link,
  115. Image,
  116. Fullscreen,
  117. // CodeView,
  118. } from "element-tiptap";
  119. import TipModal from "../../../components/TipModal";
  120. import Loading from "../../data/components/UploadLoading";
  121. import helpButton from "../custom_extensions/helpButton/index";
  122. import CodeView from "../custom_extensions/CodeView/index";
  123. import { php_url } from "../../../config/env";
  124. import axiosPhp from "axios";
  125. export default {
  126. components: { TipModal, Loading },
  127. data() {
  128. return {
  129. tipFlag: false,
  130. tipText: "",
  131. noticeTitle: "",
  132. InfoType: "",
  133. title: this.$route.query && this.$route.query.title,
  134. areaList: ["全区", "北区", "南区", "东区"], // 按区域添加
  135. extensions: [
  136. // new Preview(),
  137. // new Print(),
  138. // new SelectAll(),
  139. new Bold({ bubble: false }), // render command-button in bubble menu.
  140. new Italic(),
  141. new Strike(),
  142. new Link(),
  143. new Image(),
  144. new Fullscreen(),
  145. new CodeView(), //源码
  146. new Doc(),
  147. new Text(),
  148. new Paragraph(),
  149. new Doc(),
  150. new Text(),
  151. new Paragraph(),
  152. new Heading({ level: 5 }),
  153. new Code(),
  154. new Blockquote(),
  155. new BulletList(),
  156. new OrderedList(),
  157. new ListItem(),
  158. new CodeBlock(),
  159. new TodoList(),
  160. new TodoItem(),
  161. new Table(),
  162. new TableHeader(),
  163. new TableRow(),
  164. new TableCell(),
  165. new TextAlign(),
  166. new LineHeight(),
  167. new Indent(),
  168. new HorizontalRule(),
  169. new HardBreak(),
  170. new TrailingNode(),
  171. new TextColor(),
  172. new TextHighlight(),
  173. new FormatClear(),
  174. new FontType(),
  175. new FontSize(),
  176. new History(),
  177. new helpButton({ bubble: false }),
  178. ],
  179. content: "",
  180. unifiedUrl: "/lexus_php/api/",
  181. fileDes: [], // 上传的文件名,
  182. file: [],
  183. tipModalFlag: false,
  184. tipModalText: "",
  185. uploading: false,
  186. contentParam: {},
  187. noticeId: "",
  188. delFileIds: [],
  189. editFileLength: "",
  190. allDataNameList: [],
  191. };
  192. },
  193. computed: {},
  194. methods: {
  195. addNotice(id) {
  196. let requestURL, paramData;
  197. this.checkName();
  198. if (!this.tipFlag) {
  199. if (id) {
  200. //编辑
  201. requestURL = "notice_update.php";
  202. paramData = new FormData();
  203. paramData.append("title", this.contentParam.title);
  204. paramData.append("area", this.contentParam.area);
  205. paramData.append("content", this.contentParam.content);
  206. paramData.append("id", id);
  207. console.log(this.delFileIds);
  208. console.log(this.delFileIds.length);
  209. if (this.delFileIds.length) {
  210. let delFileStr = this.delFileIds.join(",");
  211. paramData.append("del_file_ids", delFileStr);
  212. }
  213. if (this.contentParam.files && this.contentParam.files.length === 0) {
  214. paramData.append("file_num", "0");
  215. } else {
  216. let count = 0;
  217. let len = this.file.length;
  218. this.file.forEach((item) => {
  219. count++;
  220. paramData.append("file" + count, item);
  221. });
  222. paramData.append("file_num", len);
  223. }
  224. } else {
  225. //新增
  226. requestURL = "notice_add.php";
  227. paramData = new FormData();
  228. paramData.append("title", this.contentParam.title);
  229. paramData.append("area", this.contentParam.area);
  230. paramData.append("content", this.contentParam.content);
  231. if (this.file.length === 0) {
  232. paramData.append("file_num", "0");
  233. } else {
  234. let count = 0;
  235. let len = this.file.length;
  236. this.file.forEach((item) => {
  237. count++;
  238. paramData.append("file" + count, item);
  239. });
  240. paramData.append("file_num", len);
  241. }
  242. }
  243. this.uploading = true;
  244. axiosPhp({
  245. url: php_url + this.unifiedUrl + requestURL,
  246. method: "post",
  247. data: paramData,
  248. dataType: "json", //声明成功使用json数据类型回调
  249. cache: false,
  250. processData: false,
  251. contentType: false,
  252. })
  253. .then((res) => {
  254. this.uploading = false;
  255. if (res.data.code === 200) {
  256. this.tipModalFlag = true;
  257. if (id) {
  258. this.tipModalText = "更新成功!";
  259. } else {
  260. this.tipModalText = "新增成功!";
  261. }
  262. } else {
  263. alert(res.data.message);
  264. }
  265. })
  266. .catch((err) => {
  267. alert(err);
  268. });
  269. }
  270. },
  271. // 关闭提示框
  272. closeTipModal: function () {
  273. this.tipModalFlag = false;
  274. this.$router.push({ path: "/changShang" });
  275. },
  276. // 获取文件,文件名
  277. getFileInfo: function (event) {
  278. let file = event.target.files;
  279. file.forEach((item) => {
  280. this.file.push(item);
  281. this.contentParam.files.push(item);
  282. });
  283. },
  284. // 删除文件
  285. deleteFile: function (i, item) {
  286. if (this.noticeId && this.editFileLength > this.delFileIds.length) {
  287. this.delFileIds.push(item.file_id);
  288. }
  289. this.file.splice(i, 1);
  290. this.contentParam.files.splice(i, 1);
  291. },
  292. // 保证多选框东区和其他的多选框互斥
  293. clickCheckbox(i) {
  294. let list = this.contentParam.area;
  295. let include = list.indexOf("全区");
  296. if (i === 0) {
  297. this.contentParam.area = [];
  298. return;
  299. }
  300. if (include >= 0) {
  301. this.contentParam.area.splice(0, 1);
  302. }
  303. },
  304. backToPre() {
  305. this.$router.push({
  306. path: "/changShang",
  307. query: {},
  308. });
  309. },
  310. // 转地区的格式
  311. areaToList() {
  312. this.contentParam = this.$route.query || {};
  313. const areaList = this.contentParam.area.split(",");
  314. this.contentParam.area = areaList;
  315. },
  316. getDataList: function (data = {}) {
  317. axiosPhp({
  318. method: "post",
  319. url: php_url + this.unifiedUrl + "notice_list.php",
  320. data,
  321. })
  322. .then((res) => {
  323. if (res.data.code === 200) {
  324. res.data.data.forEach((element) => {
  325. if(element.title !==this.title){
  326. this.allDataNameList.push(element.title);
  327. }
  328. });
  329. }
  330. })
  331. .catch((err) => {
  332. console.log(err);
  333. });
  334. },
  335. // 名字不重复,隐藏提示
  336. hideTip: function () {
  337. this.tipText = "资料名称不能重复,请重新输入";
  338. this.tipFlag = false;
  339. },
  340. // 检查名字是否重复 失去焦点判断
  341. checkName: function () {
  342. // 去前后空格
  343. this.contentParam.title = this.contentParam.title.replace(
  344. /(^\s*)|(\s*$)/g,
  345. ""
  346. );
  347. let include = this.allDataNameList.indexOf(this.contentParam.title);
  348. if (!this.contentParam.title) {
  349. this.tipText = "资料名不能为空";
  350. this.tipFlag = true;
  351. return;
  352. } else if (include >= 0) {
  353. this.tipText = "资料名称不能重复,请重新输入";
  354. this.tipFlag = true;
  355. return;
  356. }
  357. },
  358. },
  359. mounted() {
  360. this.getDataList();
  361. this.areaToList();
  362. this.noticeId = this.contentParam.id;
  363. if (this.contentParam.files) {
  364. this.editFileLength = this.contentParam.files.length;
  365. }
  366. },
  367. created() {},
  368. };
  369. </script>
  370. <style scoped lang="less">
  371. .fuWenBen {
  372. position: relative;
  373. left: 85px;
  374. top: -40px;
  375. width: 950px;
  376. }
  377. .operationStyle {
  378. display: flex;
  379. justify-content: center;
  380. }
  381. .operationStyle button:nth-child(1) {
  382. margin-right: 36px;
  383. }
  384. .operationStyle button {
  385. border-radius: 5px;
  386. width: 100px;
  387. height: 36px;
  388. }
  389. .Line5 button {
  390. border-radius: 5px;
  391. width: 100px;
  392. height: 23px;
  393. vertical-align: middle;
  394. }
  395. /* .operationStyle button:nth-child(2){
  396. display: flex;
  397. justify-content: center;
  398. } */
  399. .focusStyle {
  400. border: 1px solid #ccc;
  401. line-height: 20px;
  402. color: #555555;
  403. outline: none;
  404. position: absolute;
  405. }
  406. .focusStyle:focus {
  407. animation: shadowAni 200ms linear forwards;
  408. }
  409. .Line {
  410. height: 50px;
  411. }
  412. .Line span {
  413. width: 80px;
  414. height: 36px;
  415. display: inline-flex;
  416. vertical-align: middle;
  417. line-height: 36px;
  418. justify-content: flex-end;
  419. margin-right: 8px;
  420. }
  421. .areaBox {
  422. display: flex;
  423. }
  424. .areaBox span {
  425. width: 30px;
  426. }
  427. .areaBox input {
  428. vertical-align: middle;
  429. }
  430. .Line3 {
  431. display: flex;
  432. }
  433. .Line4 span {
  434. line-height: 10px;
  435. }
  436. .Line4 {
  437. margin-top: 9px;
  438. height: auto;
  439. }
  440. .Line5 span {
  441. position: relative;
  442. }
  443. .Line5 button {
  444. margin-left: 64px;
  445. }
  446. .Line1 input {
  447. height: 24px;
  448. }
  449. .Line2 select {
  450. vertical-align: middle;
  451. width: 120px;
  452. }
  453. .uploadFile {
  454. display: flex;
  455. margin-top: 35px;
  456. min-height: 100px;
  457. .title {
  458. margin-right: 8px;
  459. height: 20px;
  460. line-height: 20px;
  461. margin-left: 5%;
  462. }
  463. .fileDes {
  464. margin-left: 20px;
  465. width: 500px;
  466. overflow: hidden; /* 超出一行文字自动隐藏 */
  467. text-overflow: ellipsis; /* 文字隐藏后添加省略号 */
  468. white-space: nowrap; /* 强制不换行 */
  469. p {
  470. height: 30px;
  471. line-height: 30px;
  472. .deleteFile {
  473. font-size: 20px;
  474. margin-left: 20px;
  475. height: 30px;
  476. line-height: 30px;
  477. // color: #0056a0;
  478. &:hover {
  479. cursor: pointer;
  480. }
  481. }
  482. }
  483. }
  484. label {
  485. height: 30px;
  486. line-height: 30px;
  487. width: 72px;
  488. background-color: #0056a0;
  489. color: #fff;
  490. text-align: center;
  491. font-size: 14px;
  492. border-radius: 5px;
  493. input {
  494. display: none;
  495. }
  496. }
  497. }
  498. </style>