memos.html 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
  6. <title>memos记录</title>
  7. <script src="js/util.js"></script>
  8. <script src="js/login.js"></script>
  9. <style>
  10. body {
  11. font-family: Lyon-Text, Georgia, "Songti SC", SimSun, serif;
  12. }
  13. .vditor-reset{
  14. font-family: Lyon-Text, Georgia, "Songti SC", SimSun, serif !important;
  15. }
  16. img {
  17. border: 1px solid #b7b6b6;
  18. }
  19. .img {
  20. border: 1px solid #b7b6b6;
  21. max-width: 200px;
  22. max-height: 200px;
  23. margin: 10px 10px 0 0 !important;
  24. cursor: pointer
  25. }
  26. .editClass button {
  27. display: inline;
  28. /*margin-top: 5px;*/
  29. margin-left: 30px;
  30. }
  31. .contentLine div {
  32. margin: 5px 0 0;
  33. }
  34. .border {
  35. /*border: 1px solid #b7b6b6;*/
  36. border-radius: 5px;
  37. padding: 10px;
  38. background-color: white;
  39. }
  40. body {
  41. background-color: #f4f4f5;
  42. }
  43. .myTop {
  44. position: fixed;
  45. top: 0;
  46. background-image: url("./img/gray.png");
  47. /* 背景铺满整个div*/
  48. background-size: 100% 100%;
  49. width: 100%;
  50. padding: 10px;
  51. z-index: 100;
  52. }
  53. .myText {
  54. border: 1px solid #d2d2d2;
  55. }
  56. .vditor-reset {
  57. padding: 10px 20px !important;
  58. }
  59. .vditor-toolbar {
  60. display: none;
  61. }
  62. </style>
  63. <script src="js/vue.min.js"></script>
  64. <script src="elementUI/index.js"></script>
  65. <link rel="stylesheet" href="elementUI/index.css">
  66. <link rel="stylesheet" href="css/vditor.css">
  67. <script src="js/vditor.js"></script>
  68. </head>
  69. <body>
  70. <div id="app">
  71. <div id="all" style="max-width: 1500px; margin: 0 auto">
  72. <div class="myTop">
  73. <el-link href="https://memos.tianyunperfect.cn/">memos主页</el-link>
  74. <el-button @click="page = page - 1;search()" :disabled="page === 1">上一页</el-button>
  75. <el-input type="number" style="width: 80px;" v-model="page" @change="search"></el-input>
  76. <el-button @click="page = page + 1;search()">下一页</el-button>
  77. <el-select v-model="size" placeholder="请选择" style="width: 80px" @change="search">
  78. <el-option
  79. v-for="item in [10, 20, 50, 100]"
  80. :key="item"
  81. :label="item"
  82. :value="item">
  83. </el-option>
  84. </el-select>
  85. <!--输入框,绑定回车事件,触发查询-->
  86. <el-input style="margin-left: 30px; width: 20vw; padding-left: 10px" placeholder="关键字" v-model="searchStr" @change="searchStrChange"></el-input>
  87. <el-input style="margin-left: 30px; width: 20vw; padding-left: 10px" placeholder="AI 问答" v-model="searchStr2" @change="searchStrChange2"></el-input>
  88. <br><br>
  89. <div></div>
  90. <div style="display: flex;align-items:stretch; width: 60vw">
  91. <!-- 创建一个用于编辑的容器 -->
  92. <el-input
  93. @paste.native="handlePaste"
  94. @keydown.enter.native="keyDown"
  95. type="textarea"
  96. :autosize={minRows:2}
  97. placeholder="记录内容"
  98. @input="localStorage.setItem('contentStr', contentStr)"
  99. v-model="contentStr">
  100. </el-input>
  101. <!-- 添加发送按钮 -->
  102. <el-button style="margin-left: 20px; width: 10%; font-size: 2rem" @click="sendData" :disabled="!sendBtnAble">记录</el-button>
  103. <el-button style="margin-left: 20px; width: 10%; font-size: 1rem" @click="mergeByIds">合并</el-button>
  104. </div>
  105. <div style="display: flex">
  106. <div v-for="item in tmpFileIds">
  107. <el-image v-if="item['type'].startsWith('image')"
  108. :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=150'"
  109. :preview-src-list="['https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=750']"
  110. class="img"></el-image>
  111. <audio controls v-if="item['type'].startsWith('audio')">
  112. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/ogg">
  113. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/mpeg">
  114. 您的浏览器不支持 audio 元素。
  115. </audio>
  116. <video width="320" height="240" controls v-if="item['type'].startsWith('video')">
  117. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/mp4">
  118. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/ogg">
  119. 您的浏览器不支持 HTML5 video 元素。
  120. </video>
  121. <el-link v-if="item['type'].startsWith('application')" :href="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" target="_blank">{{item['filename']}}</el-link>
  122. <div @click="removeTmp(item)">删除</div>
  123. </div>
  124. </div>
  125. <!-- 添加多选按钮 -->
  126. <div style="display: flex;">
  127. <div>
  128. <el-checkbox-group v-model="tagChecked" @change="checkChange1()">
  129. <el-checkbox-button v-for="tag in allTags" :label="tag"></el-checkbox-button>
  130. </el-checkbox-group>
  131. </div>
  132. <div style="margin-left: 20px; display: flex;align-items: center">
  133. <el-switch
  134. @change="duoxuanChange"
  135. v-model="duoxuan"
  136. active-text="多选"
  137. inactive-text="单选"
  138. >
  139. </el-switch>
  140. </div>
  141. </div>
  142. <div id="tags"></div>
  143. </div>
  144. <div style="margin-top: 180px"></div>
  145. <div v-if="searchStr2" style="margin: 10px; padding: 10px">
  146. <el-input v-model="searchResStr" type="textarea" :autosize="{minRows: 1}" readonly="true"></el-input>
  147. </div>
  148. <div >
  149. <div v-for="item in contentList">
  150. <el-row style="margin: 10px; padding: 10px" class="border">
  151. <el-col :span="18" class="contentLine">
  152. <div style="display: flex">
  153. <el-date-picker
  154. v-model="item.created_ts"
  155. type="datetime"
  156. readonly="true"
  157. placeholder="选择日期时间">
  158. </el-date-picker>
  159. <div style="margin-left: 20px">
  160. <el-checkbox-button v-for="tag in commonTags" :label="tag" :key="item"
  161. @change="checked=>checkChange(checked,item,tag)"
  162. :checked="isChooseTag(item,tag)">{{tag}}
  163. </el-checkbox-button>
  164. </div>
  165. </div>
  166. <div class="myText" @dblclick="edit(item)">
  167. <!-- <el-input v-model="item.content" type="textarea" :autosize="{minRows: 1}" readonly="true"></el-input>-->
  168. <div :id="item.resource_name"></div>
  169. </div>
  170. <div>
  171. <div v-for="item in resourceMap[item.id]">
  172. <el-image v-if="item['type'].startsWith('image')"
  173. :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=150'"
  174. :preview-src-list="['https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=750']"
  175. class="img">
  176. </el-image>
  177. <audio controls v-if="item['type'].startsWith('audio')">
  178. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/ogg">
  179. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/mpeg">
  180. 您的浏览器不支持 audio 元素。
  181. </audio>
  182. <video width="320" height="240" controls v-if="item['type'].startsWith('video')">
  183. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/mp4">
  184. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/ogg">
  185. 您的浏览器不支持 HTML5 video 元素。
  186. </video>
  187. <el-link v-if="item['type'].startsWith('application')" :href="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" target="_blank">{{item['filename']}}</el-link>
  188. </div>
  189. </div>
  190. </el-col>
  191. <el-col :span="4" style="display: flex">
  192. <div class="editClass">
  193. <el-button size="small" @click="window.open('https://memos.tianyunperfect.cn/m/' + item.resource_name)">跳转</el-button>
  194. <br>
  195. <br>
  196. <el-button size="small" @click="edit(item)">编辑</el-button>
  197. </div>
  198. <div class="editClass">
  199. <el-button size="small" @click="archive(item)">归档</el-button>
  200. <br>
  201. <br>
  202. <el-button size="small" type="warning" @click="del(item)">删除</el-button>
  203. </div>
  204. <div class="editClass" style="margin-left: 30px">
  205. <el-checkbox :value="selectedIds.includes(item.id)" @change="handleCheckboxChange(item.id, $event)">合并</el-checkbox>
  206. </div>
  207. </el-col>
  208. </el-row>
  209. </div>
  210. </div>
  211. </div>
  212. <el-dialog
  213. title="提示"
  214. :visible.sync="dialogVisible"
  215. width="60%"
  216. >
  217. <div v-if="tmpItem.id" class="contentLine">
  218. <div>
  219. <el-date-picker
  220. v-model="tmpItem.created_ts"
  221. type="datetime"
  222. value-format="yyyy-MM-ddTHH:mm:ss"
  223. placeholder="选择日期时间">
  224. </el-date-picker>
  225. </div>
  226. <div>
  227. <el-input
  228. @paste.native="handlePaste2"
  229. ref="contentEdit" v-model="tmpItem.content" type="textarea" :autosize="{minRows: 2}"></el-input>
  230. </div>
  231. <div style="display: flex">
  232. <div v-for="item in cloneFileIds">
  233. <el-image v-if="item['type'].startsWith('image')"
  234. :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=150'"
  235. :preview-src-list="['https://memos_assert.tianyunperfect.cn/' + item['internal_path'] + '?width=750']"
  236. class="img">
  237. </el-image>
  238. <audio controls v-if="item['type'].startsWith('audio')">
  239. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/ogg">
  240. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="audio/mpeg">
  241. 您的浏览器不支持 audio 元素。
  242. </audio>
  243. <video width="320" height="240" controls v-if="item['type'].startsWith('video')">
  244. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/mp4">
  245. <source :src="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" type="video/ogg">
  246. 您的浏览器不支持 HTML5 video 元素。
  247. </video>
  248. <el-link v-if="item['type'].startsWith('application')" :href="'https://memos_assert.tianyunperfect.cn/' + item['internal_path']" target="_blank">{{item['filename']}}</el-link>
  249. <div @click="delPic(img)">删除</div>
  250. </div>
  251. </div>
  252. </div>
  253. <span slot="footer" class="dialog-footer">
  254. <el-button @click="dialogVisible = false">取 消</el-button>
  255. <el-button type="primary" @click="confirmSubmit">确 定</el-button>
  256. </span>
  257. </el-dialog>
  258. </div>
  259. <!-- 引入Quill库 -->
  260. <!--<script src="./js/cdn.quilljs.com_1.3.6_quill.js"></script>-->
  261. <!--异步请求示例:requestUtil.sync('https://jsonplaceholder.typicode.com/posts/1', 'post', data, headers) .then(data => console.log(data))-->
  262. <script>
  263. // if (getQueryString("id") !== "tianyunperfect") {
  264. // // location.href = "http://127.0.0.1";
  265. // }
  266. let authStr = "bearer eyJhbGciOiJIUzI1NiIsImtpZCI6InYxIiwidHlwIjoiSldUIn0.eyJuYW1lIjoidGlhbnl1bnBlcmZlY3QiLCJpc3MiOiJtZW1vcyIsInN1YiI6IjEiLCJhdWQiOlsidXNlci5hY2Nlc3MtdG9rZW4iXSwiaWF0IjoxNzA5MTc5NTUyfQ.LFxWB4efya1sL7VoJ42xpXxbAip-udT_Kx2OwZ8Y3-E";
  267. let myHeaders = {
  268. 'Content-type': 'application/json',
  269. 'Authorization': authStr
  270. };
  271. function getRandomId() {
  272. return Math.random().toString(36).substr(2);
  273. }
  274. let vm = new Vue({
  275. el: '#app',
  276. data: {
  277. searchStr2: '',
  278. searchResStr: '',
  279. selectedIds: [],
  280. duoxuan: false,
  281. tmpItem: {},
  282. dialogVisible: false,
  283. page: 1,
  284. size: 20,
  285. searchStr: '',
  286. contentStr: '',
  287. tagChecked: [],
  288. allTags: [],
  289. contentList: [],
  290. sendBtnAble: true,
  291. resourceMap: {}, // 资源map,
  292. commonTags: ['todo'],
  293. upload_url: 'https://memos.tianyunperfect.cn/api/v1/resource/blob',
  294. tmpFileIds: [],
  295. cloneFileIds: []
  296. },
  297. watch: {
  298. page: function () {
  299. this.search();
  300. },
  301. size: function () {
  302. this.search();
  303. },
  304. contentList: function () {
  305. console.log(1);
  306. this.$nextTick(() => {
  307. console.log(2);
  308. this.contentList.forEach(item => {
  309. this.resetView(item);
  310. // let ed = new Vditor(item.resource_name, {
  311. // cdn: 'https://ld246.com/js/lib/vditor',
  312. // // height: 360,
  313. // toolbarConfig: {
  314. // pin: true,
  315. // },
  316. // // preview: {
  317. // // theme:{
  318. // // path: ''
  319. // // }
  320. // // },
  321. // theme: 'classic',
  322. // cache: {
  323. // enable: false,
  324. // },
  325. // after: () => {
  326. // ed.setValue(item.content)
  327. // },
  328. // })
  329. })
  330. });
  331. },
  332. },
  333. mounted() {
  334. if (!checkLogin()) {
  335. return;
  336. }
  337. if (this.getQueryStr()) {
  338. this.searchStr = this.getQueryStr();
  339. }
  340. this.duoxuan = this.getDuoXuan();
  341. // 初始化contentStr,如果本地有缓存
  342. let item = localStorage.getItem('contentStr');
  343. if (item) {
  344. this.contentStr = item;
  345. }
  346. let queryStr = this.getQueryStr();
  347. if (queryStr) {
  348. // queryStr 解码
  349. queryStr = decodeURIComponent(queryStr);
  350. this.searchStr = queryStr;
  351. }
  352. // 解码
  353. let tagsStr = decodeURIComponent(getQueryString("tags"));
  354. if (tagsStr) {
  355. this.tagChecked = tagsStr.split(',')
  356. }
  357. this.getAllTags();
  358. this.search();
  359. requestUtil.async('https://web_history.tianyunperfect.cn/memos/getCustomMemoTags', 'get').then(res => {
  360. this.commonTags = JSON.parse(res['res'][0]['content']);
  361. });
  362. },
  363. methods: {
  364. resetView(item) {
  365. Vditor.preview(document.getElementById(item.resource_name), item.content, {
  366. cdn: 'https://ld246.com/js/lib/vditor',
  367. speech: {
  368. enable: false,
  369. },
  370. anchor: 1,
  371. after() {
  372. },
  373. })
  374. },
  375. mergeByIds() {
  376. if (this.selectedIds.length < 2) {
  377. return;
  378. }
  379. requestUtil.sync("https://web_history.tianyunperfect.cn/memos/mergeMemo", 'post', {ids: this.selectedIds}, {});
  380. location.reload();
  381. },
  382. handleCheckboxChange(id, checked) {
  383. if (checked) {
  384. this.selectedIds.push(id);
  385. } else {
  386. this.selectedIds = this.selectedIds.filter(selectedId => selectedId !== id);
  387. }
  388. console.log(this.selectedIds)
  389. },
  390. searchStrChange() {
  391. let queryStr = this.searchStr;
  392. // url编码
  393. queryStr = encodeURIComponent(queryStr);
  394. location.href = requestUtil.buildUrl(location.href, {'queryStr': queryStr})
  395. },
  396. searchStrChange2() {
  397. this.searchResStr = '';
  398. requestUtil.async('https://wx.tianyunperfect.cn/full_search?', 'post', {'search': this.searchStr2}, {}).then(res => {
  399. if (res['list']) {
  400. let resList = res['list']
  401. this.searchResStr = res['res'];
  402. this.contentList = resList;
  403. this.searchByContent();
  404. }
  405. })
  406. },
  407. duoxuanChange() {
  408. if (this.duoxuan) {
  409. this.setDuoXuan('ok');
  410. } else {
  411. this.setDuoXuan('');
  412. }
  413. },
  414. checkChange1(newVal) {
  415. console.log(this.tagChecked)
  416. if (!this.getDuoXuan()) {
  417. if (this.tagChecked.length > 1) {
  418. // 保留最后一个
  419. this.tagChecked = [this.tagChecked[this.tagChecked.length - 1]];
  420. }
  421. }
  422. location.href = requestUtil.buildUrl(location.href, {'tags': this.tagChecked.join(',')})
  423. },
  424. getQueryStr() {
  425. return getQueryString('queryStr')
  426. },
  427. getDuoXuan() {
  428. return getQueryString('duoxuan') == "ok";
  429. },
  430. setDuoXuan(ok) {
  431. location.href = requestUtil.buildUrl(location.href, {'duoxuan': ok})
  432. },
  433. removeTmp(item) {
  434. // tmpFileIds 根据id删除
  435. let index = this.tmpFileIds.findIndex(item => item.id === item.id);
  436. if (index !== -1) {
  437. this.tmpFileIds.splice(index, 1);
  438. }
  439. },
  440. delPic(img) {
  441. // 根据id从 cloneFileIds 删除
  442. let index = this.cloneFileIds.findIndex(item => item.id === img.id);
  443. if (index !== -1) {
  444. this.cloneFileIds.splice(index, 1);
  445. }
  446. },
  447. getCloneResourceIds(id) {
  448. let resourceMapElement = this.resourceMap[id];
  449. if (resourceMapElement) {
  450. return JSON.parse(JSON.stringify(resourceMapElement))
  451. }
  452. return []
  453. },
  454. uploadFile(url, file, headers = {}) {
  455. return new Promise((resolve, reject) => {
  456. const xhr = new XMLHttpRequest();
  457. xhr.open('POST', url, true); // 使用异步的方式
  458. const formData = new FormData();
  459. formData.append('file', file);
  460. for (const [key, value] of Object.entries(headers)) {
  461. xhr.setRequestHeader(key, value);
  462. }
  463. xhr.onload = function () {
  464. if (xhr.status === 200) {
  465. resolve(JSON.parse(xhr.responseText));
  466. } else {
  467. reject(new Error(xhr.statusText));
  468. }
  469. };
  470. xhr.onerror = function () {
  471. reject(new Error("Network Error"));
  472. };
  473. xhr.send(formData);
  474. });
  475. },
  476. getFileFromPaste(e) {
  477. let clipboardData = e.clipboardData; // IE
  478. if (!clipboardData) {
  479. //chrome
  480. clipboardData = e.originalEvent.clipboardData;
  481. }
  482. let items = '';
  483. items = (e.clipboardData || window.clipboardData).items;
  484. let file = null;
  485. if (!items || items.length === 0) {
  486. this.$message.error('当前浏览器不支持粘贴本地图片,请打开图片复制后再粘贴!');
  487. return;
  488. }
  489. // 搜索剪切板items
  490. for (let i = 0; i < items.length; i++) {
  491. // 限制上传文件类型
  492. if (items[i].type.indexOf('image') !== -1) {
  493. file = items[i].getAsFile();
  494. break;
  495. }
  496. }
  497. // 对复制黏贴的类型进行判断,若是非文件类型,比如复制黏贴的文字,则不会调用上传文件的函数
  498. if (file) {
  499. return file;
  500. }
  501. },
  502. handlePaste(e) {
  503. let file = this.getFileFromPaste(e);
  504. // 对复制黏贴的类型进行判断,若是非文件类型,比如复制黏贴的文字,则不会调用上传文件的函数
  505. if (file) {
  506. this.uploadFile(this.upload_url, file, {'Authorization': myHeaders['Authorization']}).then(res => {
  507. let fileId = res['id'];
  508. if (fileId) {
  509. let sourceRes = requestUtil.sync("https://web_history.tianyunperfect.cn/memos/resourceById", 'post', {ids: fileId}, {});
  510. let sourceRe = sourceRes['res'];
  511. this.tmpFileIds.push(...sourceRe)
  512. }
  513. });
  514. }
  515. },
  516. handlePaste2(e) {
  517. let file = this.getFileFromPaste(e);
  518. // 对复制黏贴的类型进行判断,若是非文件类型,比如复制黏贴的文字,则不会调用上传文件的函数
  519. if (file) {
  520. this.uploadFile(this.upload_url, file, {'Authorization': myHeaders['Authorization']}).then(res => {
  521. let fileId = res['id'];
  522. if (fileId) {
  523. let sourceRes = requestUtil.sync("https://web_history.tianyunperfect.cn/memos/resourceById", 'post', {ids: fileId}, {});
  524. let sourceRe = sourceRes['res'];
  525. this.cloneFileIds.push(...sourceRe)
  526. }
  527. });
  528. }
  529. },
  530. keyDown() {
  531. // 如果是ctrl + enter \ meta + enter 则发送
  532. if (event.ctrlKey || event.metaKey) {
  533. this.sendData();
  534. }
  535. },
  536. msg(content) {
  537. this.$message({
  538. message: content,
  539. type: 'success'
  540. });
  541. },
  542. isChooseTag(item, tag) {
  543. return item.content.indexOf("#" + tag + " ") !== -1;
  544. },
  545. checkChange(val, item, tag) {
  546. if (val) {
  547. this.addTag(item, tag);
  548. } else {
  549. this.delTag(item, tag);
  550. }
  551. this.resetView(item);
  552. },
  553. addTag(item, cTag) {
  554. let content = item.content;
  555. // 如果已经有了,就不添加
  556. let tmpTag = '#' + cTag + ' ';
  557. if (content.indexOf(tmpTag) !== -1) {
  558. return;
  559. }
  560. item.content = tmpTag + content;
  561. // 提交记录
  562. let res = requestUtil.sync('https://web_history.tianyunperfect.cn/memos/updateContent', 'post', {
  563. id: item.id,
  564. content: item.content,
  565. created_ts: item.created_ts
  566. }, {});
  567. if (res.code === 200) {
  568. this.msg('更新成功');
  569. // this.search();
  570. }
  571. },
  572. delTag(item, cTag) {
  573. let content = item.content;
  574. // 如果没有,就不删除
  575. if (content.indexOf(cTag) === -1) {
  576. return;
  577. }
  578. item.content = content.replace('#' + cTag + " ", '');
  579. // 提交记录
  580. let res = requestUtil.sync('https://web_history.tianyunperfect.cn/memos/updateContent', 'post', {
  581. id: item.id,
  582. content: item.content,
  583. created_ts: item.created_ts
  584. }, {});
  585. if (res.code === 200) {
  586. this.msg('更新成功');
  587. // this.search();
  588. }
  589. },
  590. del(item) {
  591. // 提醒是否删除
  592. this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'}).then(() => {
  593. requestUtil.async(`https://web_history.tianyunperfect.cn/memos/delete`, 'post', {id: item.id}, {}).then(res => {
  594. if (res.code === 200) {
  595. this.msg('删除成功');
  596. // 在 this.contentList 上直接去除
  597. this.contentList = this.contentList.filter(it => it.id !== item.id);
  598. }
  599. });
  600. })
  601. },
  602. archive(item) {
  603. requestUtil.async(`https://web_history.tianyunperfect.cn/memos/archive`, 'post', {id: item.id}, {}).then(res => {
  604. this.msg('归档成功');
  605. // 本地缓存更新
  606. this.contentList = this.contentList.filter(it => it.id !== item.id);
  607. });
  608. },
  609. handleClose(done) {
  610. this.dialogVisible = false;
  611. done();
  612. },
  613. confirmSubmit(done) {
  614. // 提交记录
  615. let res = requestUtil.sync('https://web_history.tianyunperfect.cn/memos/update', 'post', {
  616. id: this.tmpItem.id,
  617. content: this.tmpItem.content,
  618. created_ts: this.tmpItem.created_ts,
  619. resourceIdList: this.cloneFileIds.map(it => it.id)
  620. }, {});
  621. if (res.code === 200) {
  622. this.msg('更新成功');
  623. this.resetView(this.tmpItem);
  624. // 更新主页面的图片
  625. this.resourceMap[this.tmpItem.id] = this.cloneFileIds;
  626. // this.search();
  627. }
  628. this.dialogVisible = false;
  629. done();
  630. },
  631. edit(item) {
  632. this.tmpItem = item;
  633. this.cloneFileIds = this.getCloneResourceIds(item.id)
  634. this.dialogVisible = true;
  635. // 获取焦点
  636. this.$nextTick(() => {
  637. this.$refs.contentEdit.focus()
  638. })
  639. },
  640. isDisabled(item) {
  641. // 默认不可编辑,这个时候 没有disable属性
  642. return item['disable'] !== false;
  643. },
  644. sendData: function () {
  645. this.sendBtnAble = false;
  646. let content = this.contentStr;
  647. let categories = this.tagChecked;
  648. // 循环拼接类似 #tag #tag2 content
  649. let updatedContent = content;
  650. if (categories.length > 0) {
  651. // 循环拼接类似 #tag #tag2 content
  652. updatedContent = categories.map(tag => `#${tag}`).join(' ') + ' ' + content;
  653. }
  654. // updatedContent 去除尾部的\n,可能有多个
  655. updatedContent = updatedContent.replace(/\n+$/, '');
  656. let res = requestUtil.sync('https://memos.tianyunperfect.cn/api/v1/memo', 'post', {content: updatedContent, "resourceIdList": this.tmpFileIds.map(it => it.id)}, myHeaders);
  657. if (res['name']) {
  658. // window.location.href = `https://memos.tianyunperfect.cn/m/${res['name']}`;
  659. this.msg('记录成功');
  660. localStorage.setItem('contentStr', '');
  661. this.contentStr = '';
  662. this.tmpFileIds = []
  663. this.search();
  664. }
  665. this.sendBtnAble = true;
  666. },
  667. search: function () {
  668. document.documentElement.scrollTo(0, 0);
  669. console.log(this.tagChecked);
  670. let params = {'search': this.searchStr, tag_str: this.tagChecked.join(','), page: this.page, page_size: this.size};
  671. let url = 'https://web_history.tianyunperfect.cn/memos/list';
  672. let urlWithParams = requestUtil.buildUrl(url, params);
  673. let res = requestUtil.sync(urlWithParams, 'get', null, myHeaders);
  674. if (res.code !== 200) {
  675. return;
  676. }
  677. this.contentList = res.res;
  678. this.searchByContent();
  679. },
  680. getAllTags: function () {
  681. this.allTags = requestUtil.async('https://memos.tianyunperfect.cn/api/v1/tag', 'get', null, myHeaders).then(res => {
  682. this.allTags = res;
  683. })
  684. },
  685. searchByContent: function () {
  686. this.resourceMap = {};
  687. // contentList 循环获取里面所有的id数组
  688. let idArr = this.contentList.map(item => item['id']);
  689. // 获取资源
  690. let ids = idArr.join(',');
  691. if (!ids) {
  692. return;
  693. }
  694. let sourceRes = requestUtil.sync("https://web_history.tianyunperfect.cn/memos/resource", 'post', {ids: ids}, {});
  695. // {'code': 200, 'res': [{'memo_id': 1, 'resource_name': 'EfdmvRsodBviDQWRmDiTaV'}, {'memo_id': 4, 'resource_name': '2rY5kmn3AHsy23vK4vSskV'}, {'memo_id': 7, 'resource_name': 'FMhzJXjoTa7fdtbbCBjXnt'}]}
  696. // 循环遍历,以memo_id为key,resource_name数组为value
  697. sourceRes['res'].forEach(item => {
  698. if (this.resourceMap[item['memo_id']]) {
  699. this.resourceMap[item['memo_id']].push(item);
  700. } else {
  701. this.resourceMap[item['memo_id']] = [item];
  702. }
  703. });
  704. },
  705. }
  706. });
  707. // 如果处于编辑状态,则执行esc取消
  708. window.onkeydown = function (event) {
  709. let edit = vm.dialogVisible;
  710. if (!edit) {
  711. return;
  712. }
  713. // esc
  714. if (event.keyCode === 27) {
  715. vm.dialogVisible = false;
  716. }
  717. // 如果是meta + enter 则保存
  718. if (event.metaKey && event.keyCode === 13) {
  719. vm.confirmSubmit();
  720. }
  721. // 如果是ctrl + enter 则保存
  722. if (event.ctrlKey && event.keyCode === 13) {
  723. vm.confirmSubmit();
  724. }
  725. };
  726. </script>
  727. </body>
  728. </html>