memos.html 35 KB

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