memos.html 33 KB

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