writeNote.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. <template>
  2. <view class="container write-note">
  3. <view class="nav-bar-wrap" :style="{ height: navBarStyle.height, paddingTop: navBarStyle.paddingTop, paddingBottom: navBarStyle.paddingBottom }">
  4. <view class="content-box" :style="{ color: '#333' }">
  5. <text>发布新内容</text>
  6. <view class="arrow-left-icon">
  7. <van-icon name="arrow-left" size="20px" @click="goHandler" />
  8. </view>
  9. </view>
  10. </view>
  11. <view class="write-note-top">
  12. <view @click="topLableHandler(item)" :class="['write-text', topLableActive == item.value && 'act-top-lable']" v-for="item in topLableList" :key="item.value"> {{ item.name }}</view>
  13. </view>
  14. <view class="write-note-content">
  15. <view class="title-note"> <input v-model="articleTitle" placeholder="请输入标题" /></view>
  16. <view class="content-note">
  17. <editor id="editor" @ready="onEditorReady" v-model="advice_content" placeholder="请输入正文(更轻松的创作,上传文档,请先登录查研观向网页版)" @input="contentChange" />
  18. <view class="new-lable" @click="showPopup = true">
  19. <view style="flex-shrink: 0">+ 标签(至少添加一个)</view>
  20. <view v-for="item in industryCompanyLable" :key="item" class="lable-li active">
  21. {{ item }}
  22. <van-icon name="cross" style="margin-left: 8rpx" />
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="write-note-img">
  28. <robbyImageUpload ref="robbyImageUpload" class="image-add-upload" v-model="fileList" :server-url="uploadUrl" :header="header" :limit="6" />
  29. </view>
  30. <view class="write-note-button">
  31. <view class="draft" @click="draftBtnHandler"> 草稿箱</view>
  32. <view class="release" @click="releaseBtnHandler"> 发布</view>
  33. </view>
  34. <van-popup :show="showPopup" position="bottom" custom-style="height: 85%;" round custom-class="lable-class-popup">
  35. <viwe class="add-lable-box">
  36. <view class="add-txt"> 添加标签 <view @click="addCompleteHandler"> 完成 </view></view>
  37. <view class="select-item">
  38. <view @click="industryOfCompanyHanler(item)" v-for="item in lableList" :key="item.value" :class="['item', lableActive == item.value && 'act-item']"> {{ item.name }}</view>
  39. </view>
  40. <view class="input-box">
  41. <icon type="search" size="15" class="sea_ico" />
  42. <input v-model="columnName" placeholder="专栏名称" @confirm="searchHandle" />
  43. <view v-if="lableActive == 2" style="color: #376cbb" @click="addCompanyLableHandler">+ &nbsp;创建</view>
  44. </view>
  45. <view class="text-box"> 已选标签 <view class="one-lable-text"> 至少添加一个标签 </view></view>
  46. <view class="lable-ul">
  47. <block v-if="lableActive == 1">
  48. <view :class="['lable-li', 'active']" v-for="item in selectedLableList" :key="item">
  49. {{ item }}
  50. <van-icon name="cross" style="margin-left: 8rpx" @click="selectedLableHandle(item)" />
  51. </view>
  52. </block>
  53. <block v-else>
  54. <view :class="['lable-li', 'active']" v-for="item in companySelectedLable" :key="item">
  55. {{ item }}
  56. <van-icon name="cross" style="margin-left: 8rpx" @click="selectedLableHandle(item)" />
  57. </view>
  58. </block>
  59. </view>
  60. <view class="text-box"> 标签</view>
  61. <view class="lable-ul">
  62. <!-- 这里就不用计算属性了 不知道会不会有隐藏的问题 -->
  63. <block v-if="lableActive == 1">
  64. <view :class="['lable-li']" @click="industryLabelHandler(item)" v-for="item in industryLabel" :key="item">{{ item }}</view>
  65. </block>
  66. <block v-else>
  67. <block v-for="item in companyLable" :key="item">
  68. <view :class="['lable-li']" @click="industryLabelHandler(item)" v-if="!item.search">
  69. {{ item }}
  70. </view>
  71. </block>
  72. </block>
  73. </view>
  74. </viwe>
  75. </van-popup>
  76. </view>
  77. </template>
  78. <script>
  79. import robbyImageUpload from "../components/imageUpload.vue";
  80. import { purchaserApi, uploadurl } from "@/config/api";
  81. export default {
  82. components: { robbyImageUpload },
  83. data() {
  84. return {
  85. navBarStyle: {
  86. height: 60 + "px",
  87. paddingTop: 40 + "px",
  88. paddingBottom: "4px",
  89. },
  90. showPopup: false,
  91. fileList: [],
  92. articleTitle: "", // 标题
  93. advice_content: "",
  94. columnName: "",
  95. industryCompanyLable: [], //添加的标签
  96. lableList: [
  97. { name: "行业标签", value: 1 },
  98. { name: "公司标签", value: 2 },
  99. ], // 公司或者行业标签
  100. lableActive: 1,
  101. topLableList: [
  102. { name: "笔记", value: 1 },
  103. { name: "观点", value: 2 },
  104. ], // 笔记或者观点的标签
  105. topLableActive: 1, // 笔记或者观点的选中
  106. industryLabel: [], // 行业标签
  107. selectedLableList: [], // 行业标签已选项
  108. companyLable: [], // 公司标签
  109. companySelectedLable: [], // 公司标签已选项
  110. detailId: 0,
  111. detailDataForm: {},
  112. editorCtx: null,
  113. };
  114. },
  115. computed: {
  116. uploadUrl() {
  117. return uploadurl;
  118. },
  119. },
  120. methods: {
  121. // 初始获取导航栏
  122. initNavBar() {
  123. let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  124. this.navBarStyle = {
  125. height: menuButtonInfo.height + menuButtonInfo.top + 8 + "px",
  126. paddingTop: menuButtonInfo.top - 4 + "px",
  127. paddingBottom: "4px",
  128. };
  129. },
  130. // 添加标签完成事件
  131. addCompleteHandler() {
  132. this.industryCompanyLable = [...this.selectedLableList, ...this.companySelectedLable];
  133. this.showPopup = false;
  134. this.$nextTick(() => {
  135. this.selectedLableList = [];
  136. this.companySelectedLable = [];
  137. });
  138. },
  139. // 左上角的返回按钮
  140. goHandler() {
  141. let { Title, Content, ImgUrl, Tags } = this.detailDataForm;
  142. if (Title && Tags && (Title != this.articleTitle || (this.advice_content != Content && this.fileList.join(",") != ImgUrl) || this.industryCompanyLable.join(",") != Tags)) {
  143. uni.showModal({
  144. title: "是否保存当前修改",
  145. content: "保存的草稿可在【内容中心】查看",
  146. confirmColor: "#3385FF",
  147. cancelColor: "#606266",
  148. cancelText: "不保存",
  149. confirmText: "保存",
  150. success(res) {
  151. if (res.confirm) {
  152. uni.navigateBack();
  153. } else {
  154. console.log(11);
  155. }
  156. },
  157. });
  158. return;
  159. } else if (Title && Tags) {
  160. return;
  161. }
  162. if (this.articleTitle || this.advice_content || this.fileList > 0 || this.industryCompanyLable.length > 0) {
  163. uni.showModal({
  164. title: "是否保存当前修改",
  165. content: "保存的草稿可在【内容中心】查看",
  166. confirmColor: "#3385FF",
  167. cancelColor: "#606266",
  168. cancelText: "不保存",
  169. confirmText: "保存",
  170. success(res) {
  171. if (res.confirm) {
  172. uni.navigateBack();
  173. } else {
  174. console.log(11);
  175. }
  176. },
  177. });
  178. } else {
  179. uni.navigateBack();
  180. }
  181. },
  182. // 创建标签公司Lable
  183. addCompanyLableHandler() {
  184. if (!this.columnName) return;
  185. this.companySelectedLable.push(this.columnName);
  186. },
  187. // 行业公司标签的点击事件
  188. industryOfCompanyHanler(item) {
  189. this.lableActive = item.value;
  190. },
  191. // 内容输入框
  192. contentChange(e) {
  193. this.advice_content = e.detail.html;
  194. },
  195. // 头部 table 的点击事件
  196. topLableHandler(item) {
  197. this.topLableActive = item.value;
  198. },
  199. // 行业的标签点击事件
  200. industryLabelHandler(item) {
  201. if (this.lableActive == 1) {
  202. if (this.selectedLableList.includes(item)) {
  203. let index = this.selectedLableList.findIndex((key) => key == item);
  204. this.selectedLableList.splice(index, 1);
  205. } else {
  206. this.selectedLableList.push(item);
  207. }
  208. } else {
  209. if (this.companySelectedLable.includes(item)) {
  210. let index = this.companySelectedLable.findIndex((key) => key == item);
  211. this.companySelectedLable.splice(index, 1);
  212. } else {
  213. this.companySelectedLable.push(item);
  214. }
  215. }
  216. },
  217. // 点击取消标签的事件
  218. selectedLableHandle(item) {
  219. if (this.lableActive == 1) {
  220. let index = this.selectedLableList.findIndex((key) => key == item);
  221. this.selectedLableList.splice(index, 1);
  222. } else {
  223. let index = this.companySelectedLable.findIndex((key) => key == item);
  224. this.companySelectedLable.splice(index, 1);
  225. }
  226. },
  227. // 草稿箱
  228. draftBtnHandler() {
  229. uni.showModal({
  230. title: "是否保存当前修改",
  231. content: "保存的草稿可在【内容中心】查看",
  232. confirmColor: "#3385FF",
  233. cancelColor: "#606266",
  234. cancelText: "不保存",
  235. confirmText: "保存",
  236. success: async (res) => {
  237. if (res.confirm) {
  238. const resSave = await purchaserApi.yanxuanSpecialSave({
  239. Content: this.advice_content,
  240. title: this.articleTitle,
  241. Type: this.topLableActive,
  242. Tags: this.industryCompanyLable.join(","),
  243. ImgUrl: this.$refs.robbyImageUpload.imageList.join(","),
  244. DoType: 1,
  245. Id: this.detailId,
  246. });
  247. if (resSave.Ret === 200) {
  248. this.$util.toast("已保存至草稿箱");
  249. uni.navigateBack();
  250. }
  251. }
  252. },
  253. });
  254. },
  255. // 发布
  256. releaseBtnHandler() {
  257. uni.showModal({
  258. title: "确认发布",
  259. content: "内容将提交给管理员审核后发布,确定要提交审核吗?",
  260. confirmColor: "#3385FF",
  261. cancelColor: "#606266",
  262. success: async (res) => {
  263. if (res.confirm) {
  264. const resSave = await purchaserApi.yanxuanSpecialSave({
  265. Content: this.advice_content,
  266. title: this.articleTitle,
  267. Type: this.topLableActive,
  268. Tags: this.industryCompanyLable.join(","),
  269. ImgUrl: this.$refs.robbyImageUpload.imageList.join(","),
  270. DoType: 2,
  271. Id: this.detailId,
  272. });
  273. if (resSave.Ret === 200) {
  274. this.$util.toast("发布成功");
  275. uni.navigateBack();
  276. }
  277. }
  278. },
  279. });
  280. },
  281. searchHandle() {
  282. this.lableActive == 1 ? this.getIndustryList() : this.getCompanySearch();
  283. },
  284. // 获取行业标签
  285. async getIndustryList() {
  286. const res = await purchaserApi.yanxuanSpecialIndustrySearch({
  287. Keyword: this.columnName,
  288. });
  289. if (res.Ret === 200) {
  290. this.industryLabel = res.Data;
  291. }
  292. },
  293. // 获取公司标签
  294. async getCompanySearch() {
  295. const res = await purchaserApi.yanxuanSpecialCompanySearch({
  296. Keyword: this.columnName,
  297. });
  298. if (res.Ret === 200) {
  299. this.companyLable = res.Data;
  300. }
  301. },
  302. deleteImage(e) {
  303. this.fileList = [...e.allImages];
  304. },
  305. addImage(e) {
  306. // console.log(e);
  307. this.fileList = [...e.allImages];
  308. },
  309. // 获取专栏详情
  310. async getDetaliData() {
  311. const res = await purchaserApi.yanxuanSpecialDetail({
  312. Id: this.detailId,
  313. });
  314. if (res.Ret === 200) {
  315. this.detailDataForm = res.Data;
  316. this.articleTitle = this.detailDataForm.Title;
  317. this.advice_content = this.detailDataForm.Content;
  318. setTimeout(() => {
  319. this.editorCtx.insertText({
  320. text: this.detailDataForm.Content,
  321. });
  322. }, 200);
  323. this.fileList = this.detailDataForm.ImgUrl ? this.detailDataForm.ImgUrl.split(",") : [];
  324. this.industryCompanyLable = this.detailDataForm.Tags.split(",");
  325. }
  326. },
  327. onEditorReady() {
  328. uni
  329. .createSelectorQuery()
  330. .select("#editor")
  331. .context((res) => {
  332. this.editorCtx = res.context;
  333. })
  334. .exec();
  335. },
  336. },
  337. onLoad(options) {
  338. this.detailId = Number(options.id) || 0;
  339. this.detailId > 0 && this.getDetaliData();
  340. this.initNavBar();
  341. this.getIndustryList();
  342. },
  343. };
  344. </script>
  345. <style lang="scss" scope>
  346. .write-note {
  347. .nav-bar-wrap {
  348. position: sticky;
  349. top: 0;
  350. left: 0;
  351. width: 100%;
  352. display: flex;
  353. align-items: center;
  354. z-index: 99;
  355. background-color: #fff;
  356. .content-box {
  357. position: relative;
  358. display: flex;
  359. align-items: center;
  360. width: 100%;
  361. justify-content: center;
  362. color: #fff;
  363. font-size: 34rpx;
  364. .arrow-left-icon {
  365. position: absolute;
  366. display: flex;
  367. align-items: center;
  368. justify-content: center;
  369. width: 40rpx;
  370. height: 40rpx;
  371. left: 39rpx;
  372. top: 50%;
  373. transform: translateY(-50%);
  374. z-index: 99;
  375. }
  376. }
  377. }
  378. background-color: #f3f5f9;
  379. padding-bottom: 200rpx;
  380. .write-note-content {
  381. background-color: #fff;
  382. margin-top: 1rpx;
  383. padding: 30rpx;
  384. .title-note {
  385. width: 100%;
  386. height: 112rpx;
  387. display: flex;
  388. align-items: center;
  389. border-bottom: 2rpx solid #f3f5f9;
  390. }
  391. .content-note {
  392. width: 100%;
  393. height: 880rpx;
  394. padding-top: 20rpx;
  395. .ql-container {
  396. height: calc(100% - 80rpx);
  397. }
  398. .new-lable {
  399. margin-top: 20px;
  400. color: #376cbb;
  401. display: flex;
  402. width: 100%;
  403. overflow: hidden;
  404. overflow-x: auto;
  405. .lable-li {
  406. flex-shrink: 0;
  407. display: flex;
  408. align-items: center;
  409. margin: 0 20rpx 30rpx 0;
  410. height: 56rpx;
  411. padding: 0 24rpx;
  412. border-radius: 153rpx;
  413. background-color: #f8f8fa;
  414. }
  415. .active {
  416. background-color: #376cbb;
  417. color: #fff;
  418. }
  419. }
  420. }
  421. }
  422. .write-note-img {
  423. margin-top: 20rpx;
  424. background-color: #fff;
  425. width: 100%;
  426. padding: 20rpx;
  427. .image-add-upload {
  428. width: 100%;
  429. }
  430. }
  431. .write-note-button {
  432. position: fixed;
  433. width: 100%;
  434. bottom: 50rpx;
  435. left: 0rpx;
  436. z-index: 99;
  437. display: flex;
  438. padding: 0 35rpx;
  439. padding-bottom: constant(safe-area-inset-bottom);
  440. padding-bottom: env(safe-area-inset-bottom);
  441. .draft {
  442. margin-right: 20rpx;
  443. display: flex;
  444. align-items: center;
  445. justify-content: center;
  446. width: 216rpx;
  447. height: 72rpx;
  448. color: #376cbb;
  449. background-color: #e5efff;
  450. border-radius: 9rpx;
  451. }
  452. .release {
  453. flex: 1;
  454. display: flex;
  455. align-items: center;
  456. justify-content: center;
  457. height: 72rpx;
  458. border-radius: 9rpx;
  459. color: #ffff;
  460. background-color: #376cbb;
  461. }
  462. }
  463. .lable-class-popup {
  464. padding: 30rpx;
  465. }
  466. .add-lable-box {
  467. font-size: 28rpx;
  468. width: 100%;
  469. .add-txt {
  470. position: relative;
  471. height: 60rpx;
  472. line-height: 60rpx;
  473. font-weight: 600;
  474. font-size: 36rpx;
  475. color: #000;
  476. text-align: center;
  477. view {
  478. position: absolute;
  479. top: 0;
  480. right: 20rpx;
  481. color: #376cbb;
  482. font-size: 28rpx;
  483. }
  484. }
  485. .select-item {
  486. display: flex;
  487. margin: 20rpx 0;
  488. .item {
  489. width: 176rpx;
  490. height: 64rpx;
  491. border-radius: 100rpx;
  492. display: flex;
  493. align-items: center;
  494. justify-content: center;
  495. background-color: #f3f3f3;
  496. margin-right: 30rpx;
  497. }
  498. .act-item {
  499. color: #376cbb;
  500. background-color: #e5efff;
  501. }
  502. }
  503. .input-box {
  504. background-color: #f3f3f3;
  505. display: flex;
  506. align-items: center;
  507. height: 80rpx;
  508. width: 100%;
  509. position: relative;
  510. padding-left: 50rpx;
  511. padding-right: 20rpx;
  512. input {
  513. background-color: #f3f3f3;
  514. flex: 1;
  515. height: 80rpx;
  516. }
  517. .sea_ico {
  518. position: absolute;
  519. width: 31rpx;
  520. height: 31rpx;
  521. left: 10rpx;
  522. top: 50%;
  523. transform: translateY(-50%);
  524. }
  525. }
  526. .text-box {
  527. color: #333;
  528. font-size: 28rpx;
  529. font-weight: 600;
  530. display: flex;
  531. justify-content: space-between;
  532. margin: 30rpx 0;
  533. .one-lable-text {
  534. color: #999;
  535. font-size: 24rpx;
  536. font-weight: 400;
  537. }
  538. }
  539. .lable-ul {
  540. display: flex;
  541. flex-wrap: wrap;
  542. max-height: 500rpx;
  543. overflow: hidden;
  544. overflow-y: auto;
  545. .lable-li {
  546. flex-shrink: 0;
  547. display: flex;
  548. align-items: center;
  549. margin: 0 20rpx 30rpx 0;
  550. height: 56rpx;
  551. padding: 0 24rpx;
  552. border-radius: 153rpx;
  553. background-color: #f8f8fa;
  554. }
  555. .active {
  556. background-color: #376cbb;
  557. color: #fff;
  558. }
  559. }
  560. }
  561. .write-note-top {
  562. display: flex;
  563. background-color: #fff;
  564. padding: 15rpx 35rpx;
  565. .write-text {
  566. display: flex;
  567. align-items: center;
  568. justify-content: center;
  569. font-size: 28rpx;
  570. width: 148rpx;
  571. height: 64rpx;
  572. padding: 10rpx 32rpx 10rpx 32rpx;
  573. border-radius: 0rpx 6rpx 6rpx 0rpx;
  574. border: 1rpx solid #e7e7e7;
  575. }
  576. .act-top-lable {
  577. background-color: #376cbb;
  578. color: #fff;
  579. border: none;
  580. }
  581. }
  582. }
  583. </style>