note.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <div class="pb_content" style="background: unset">
  3. <div
  4. class="pb_content_body"
  5. style="
  6. background: #fff;
  7. padding: 0px 25px;
  8. box-sizing: border-box;
  9. border-radius: 5px;
  10. max-width: 500px !important;
  11. "
  12. >
  13. <div class="pb_head">
  14. <span>便签</span>
  15. <div class="addNote" @click="addNote">添加便签</div>
  16. </div>
  17. <div class="searchNote">
  18. <span style="width: 100%">
  19. <el-input placeholder="搜索..." v-model="noteC" clearable> </el-input>
  20. </span>
  21. <el-button type="primary" @click="selectContent">查询</el-button>
  22. </div>
  23. <div class="noteList">
  24. <div class="noteBg" v-for="(item, index) in noteList" :key="index">
  25. <!-- @change="saveNote(item.nid, item.content,type = 1)" 边写边保存 @blur点击旁边保存-->
  26. <el-input
  27. type="textarea"
  28. autosize
  29. v-model="item.content"
  30. @blur="saveNote(item.nid, item.content, (type = 1))"
  31. resize="none"
  32. >
  33. </el-input>
  34. <div class="ellipsis" @click="openTc(index)">
  35. <img src="../../assets/icon/ellipsis.png" alt="" />
  36. </div>
  37. <div class="noteHorn">
  38. <img src="../../assets/icon/noteHorn.png" alt="" />
  39. </div>
  40. <div class="tc" v-if="isNone == index + 1">
  41. <div class="first" @click="saveNote(item.nid, item.content)">
  42. <div class="save">
  43. <img src="../../assets/icon/save.png" alt="" />
  44. </div>
  45. <div>保存笔记</div>
  46. </div>
  47. <div class="first" @click="deleteNote(item.nid)">
  48. <div class="delete">
  49. <img src="../../assets/icon/deleteN.png" alt="" />
  50. </div>
  51. <div>删除笔记</div>
  52. </div>
  53. </div>
  54. </div>
  55. </div>
  56. <div class="noneDiv" @click="isNone = 0" v-if="isNone != 0"></div>
  57. </div>
  58. </div>
  59. </template>
  60. <script>
  61. export default {
  62. data() {
  63. return {
  64. tableHeight: "500px",
  65. page: 1,
  66. total: 0,
  67. formLabelWidth: "100px",
  68. userid: this.$route.query.userid,
  69. noteC: "",
  70. noteContent: "",
  71. noteList: [],
  72. isNone: 0,
  73. type: 0,
  74. };
  75. },
  76. methods: {
  77. openTc(i) {
  78. this.isNone = i + 1;
  79. },
  80. getNote() {
  81. let params = {
  82. uid: this.userid,
  83. };
  84. this.ajax
  85. .get(this.$store.state.api + "selectNote", params)
  86. .then((res) => {
  87. this.noteList = res.data[0];
  88. if (this.noteList.length == 0) {
  89. this.addNote();
  90. }
  91. })
  92. .catch((err) => {
  93. this.isLoading = false;
  94. console.error(err);
  95. });
  96. },
  97. selectContent() {
  98. let params = {
  99. cn: this.noteC,
  100. };
  101. this.ajax
  102. .get(this.$store.state.api + "selectNoteContent", params)
  103. .then((res) => {
  104. this.noteList = res.data[0];
  105. })
  106. .catch((err) => {
  107. this.$message.error("查询失败");
  108. console.error(err);
  109. });
  110. },
  111. addNote() {
  112. let params = {
  113. uid: this.userid,
  114. c: "",
  115. };
  116. this.ajax
  117. .get(this.$store.state.api + "insertNote", params)
  118. .then((res) => {
  119. this.$message({
  120. message: "新增成功",
  121. type: "success",
  122. });
  123. this.getNote();
  124. })
  125. .catch((err) => {
  126. this.$message.error("新增失败");
  127. console.error(err);
  128. });
  129. },
  130. saveNote(nid, c, type) {
  131. let params = {
  132. nid: nid,
  133. c: c,
  134. };
  135. this.ajax
  136. .get(this.$store.state.api + "updateNote", params)
  137. .then((res) => {
  138. if (type == 0) {
  139. this.$message({
  140. message: "修改成功",
  141. type: "success",
  142. });
  143. }
  144. this.getNote();
  145. })
  146. .catch((err) => {
  147. this.$message.error("修改失败");
  148. console.error(err);
  149. });
  150. },
  151. deleteNote(nid) {
  152. let params = {
  153. nid: nid,
  154. };
  155. this.ajax
  156. .get(this.$store.state.api + "deleteNote", params)
  157. .then((res) => {
  158. this.$message({
  159. message: "删除成功",
  160. type: "success",
  161. });
  162. this.getNote();
  163. })
  164. .catch((err) => {
  165. this.$message.error("删除失败");
  166. console.error(err);
  167. });
  168. },
  169. },
  170. created() {
  171. this.getNote();
  172. },
  173. };
  174. </script>
  175. <style scoped>
  176. .pb_head {
  177. display: flex;
  178. justify-content: space-between;
  179. }
  180. .pb_head {
  181. margin: 0 !important;
  182. width: 100% !important;
  183. border-bottom: 1px solid #ebebeb;
  184. padding: 10px 0;
  185. }
  186. .addNote {
  187. background: #458bdf;
  188. color: #fff;
  189. font-size: 16px;
  190. width: 110px;
  191. text-align: center;
  192. line-height: 40px;
  193. height: 40px;
  194. border-radius: 5px;
  195. cursor: pointer;
  196. }
  197. .searchNote {
  198. display: flex;
  199. margin: 20px 0;
  200. }
  201. .searchNote >>> .el-input__inner {
  202. background: #f1f1f1;
  203. }
  204. .searchNote >>> .el-button--primary {
  205. margin-left: 20px;
  206. background-color: #2268bc !important;
  207. }
  208. .noteList {
  209. padding: 5px 0;
  210. }
  211. .noteBg {
  212. background: #fff7d1;
  213. min-height: 100px;
  214. position: relative;
  215. border-radius: 5px;
  216. margin-bottom: 15px;
  217. }
  218. .noteHorn {
  219. width: 1rem;
  220. position: absolute;
  221. bottom: -5px;
  222. right: 0;
  223. }
  224. .ellipsis {
  225. width: 2rem;
  226. position: absolute;
  227. top: 5px;
  228. right: 20px;
  229. cursor: pointer;
  230. z-index: 99;
  231. }
  232. .noteHorn > img,
  233. .ellipsis > img,
  234. .save > img,
  235. .delete > img {
  236. width: 100%;
  237. height: 100%;
  238. }
  239. .noteBg >>> .el-textarea__inner {
  240. background: transparent;
  241. border: none;
  242. min-height: 100px !important;
  243. padding-top: 10px;
  244. }
  245. .tc {
  246. position: absolute;
  247. top: 30px;
  248. width: 110px;
  249. background: #fffffb;
  250. right: -35px;
  251. box-shadow: 1px 2px 4px 0px #e8e8e8;
  252. z-index: 99;
  253. }
  254. .first {
  255. display: flex;
  256. flex-direction: row;
  257. justify-content: center;
  258. align-items: center;
  259. height: 40px;
  260. cursor: pointer;
  261. }
  262. .save,
  263. .delete {
  264. width: 1.5rem;
  265. }
  266. .noneDiv {
  267. height: 100%;
  268. background: transparent;
  269. position: absolute;
  270. top: 0;
  271. left: 50%;
  272. transform: translate(-50%, 0);
  273. z-index: 9;
  274. width: 100%;
  275. }
  276. .first > div:nth-child(2) {
  277. margin-left: 5px;
  278. margin-top: -5px;
  279. }
  280. </style>