index.vue 2.7 KB
Newer Older
1 2 3 4 5 6
<template>
    <div class="container w-auto m-auto bg-gray-200 mb-10">
        
        <div class="p-4">
            
            <span>添加内容</span>
7
            <textarea class="block my-2 w-full" v-model="newContent"></textarea>
8
            <button class="bg-gray-300 py-2  px-4 rounded hover:bg-gray-400" @click="add"> add</button>
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
            <button class="bg-gray-300 py-2  px-4 rounded hover:bg-gray-400 ml-2" @click="search"> search</button>
            


            <div class="w-full mt-4">
                <table class="table-auto w-full bg-gray-200 text-left">
                    <thead>
                        <tr class="h-10 *:border-b *:border-slate-300 *:pl-2 *:bold">
                            <th >ID</th>
                            <th >内容</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr v-for="item in list" class="*:h-12 *:border-b *:border-slate-300 *:pl-2 *:hover:bg-gray-300">
                            <td >{{ item._id }}</td>
                            <td>{{ item.content }}</td>
                            <td class="*:py-1  *:px-4 *:rounded-md *:mr-2 *:text-gray-100">
                                <button  @click="deleteItem(item)" class="bg-orange-400 hover:bg-orange-500"> 删除</button>
                                <button  @click="updateItem(item)" class="bg-blue-400 hover:bg-blue-500"> 更新</button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            

36 37 38 39 40 41 42
        </div>
    </div>
    
</template>
<script>
import Config from '../../js/config'
import RepEs from '../../js/repEs'
43 44
import { MessagePlugin } from 'tdesign-vue-next';

45

46
const esClient = new RepEs(Config.getData().data.ext)
47 48 49 50 51 52
export default {
    name: 'contentIndex',
    components: {
    },
    data() {
        return {
53 54
            newContent: '测试内容',
            list: []
55 56 57 58
        }
    },
    methods: {
        add () {
59
            debugger
60
            esClient.add(this.newContent)
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
        },
        search () {
            esClient.query(this.newContent).then(res => {
                console.info('query')
                console.info(res)
                this.list = res
            })
        },
        updateItem (item) {
            esClient.update(item._id, item.content).then(res => {
                MessagePlugin.success({ content: '更新成功', placement: 'center' })
            })

        },
        deleteItem (item) {
            esClient.delete(item._id).then(res => {
                MessagePlugin.success({ content: '删除成功', placement: 'center' })
            })
        },

81 82 83
    }
}
</script>