Skip to content

Commit

Permalink
Merge branch 'feature/20230808' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
NMTuan committed Aug 13, 2023
2 parents ffe3de1 + c56ec5c commit 1266ee9
Show file tree
Hide file tree
Showing 9 changed files with 1,131 additions and 709 deletions.
Binary file added assets/images/sponsor/alipay.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/sponsor/wepay.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
184 changes: 184 additions & 0 deletions components/database/fields.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<!--
* @Author: NMTuan
* @Email: NMTuan@qq.com
* @Date: 2023-08-08 07:34:55
* @LastEditTime: 2023-08-13 11:16:19
* @LastEditors: NMTuan
* @Description:
* @FilePath: \laf_curd\components\database\fields.vue
-->
<template>
<div>
<!-- 按钮 -->
<el-button @click="dialogVisible = true">
<div class="i-ri-table-line text-base"> </div>
</el-button>
<!-- 弹窗 -->
<el-dialog v-model="dialogVisible" title="Fields" :close-on-click-modal="false" :close-on-press-escape="false"
@open="handlerOpen" width="80%">

<el-table :data="fields" class="w-full" :row-class-name="handlerRowClass">
<el-table-column :label="col.label" :key="col.key" :width="col.width" v-for="col in columns">
<template #default="{ row, column, $index }">
<div v-if="column.rawColumnKey === 'key' && exitsCol(row.key)">{{ row[column.rawColumnKey] }}</div>
<div v-else-if="column.rawColumnKey === 'position'" class="flex items-center justify-around">
<el-link :underline="false" @click="handlerSort('top', $index)"
:disabled="sortDisabled('top', $index)">
<div class="i-ri-skip-up-line text-lg"></div>
</el-link>
<el-link :underline="false" @click="handlerSort('up', $index)"
:disabled="sortDisabled('up', $index)">
<div class="i-ri-arrow-up-s-line text-lg"></div>
</el-link>
<el-link :underline="false" @click="handlerSort('down', $index)"
:disabled="sortDisabled('down', $index)">
<div class="i-ri-arrow-down-s-line text-lg"></div>
</el-link>
<el-link :underline="false" @click="handlerSort('end', $index)"
:disabled="sortDisabled('end', $index)">
<div class="i-ri-skip-down-line text-lg"></div>
</el-link>
</div>
<el-popconfirm v-else-if="column.rawColumnKey === 'remove'" confirm-button-text="删除"
confirm-button-type="danger" cancel-button-text="取消" cancel-button-type="default" hide-icon
:title="`确定要删除“${row.title || row.key || '此字段'}”吗?`" width="240"
@confirm="handlerRemove($index)">
<template #reference>
<div class="i-ri-close-line text-lg cursor-pointer" hover="text-red-600"></div>
</template>
</el-popconfirm>
<el-input-number v-else-if="column.rawColumnKey === 'width'" size=""
v-model="fields[$index][column.rawColumnKey]" :min="150" :step="10" />
<el-radio-group v-else-if="column.rawColumnKey === 'align'" size=""
v-model="fields[$index][column.rawColumnKey]">
<el-radio-button label="">居左</el-radio-button>
<el-radio-button label="center">居中</el-radio-button>
<el-radio-button label="right">居右</el-radio-button>
</el-radio-group>
<el-radio-group v-else-if="column.rawColumnKey === 'fixed'" size=""
v-model="fields[$index][column.rawColumnKey]">
<el-radio-button label="">不浮</el-radio-button>
<el-radio-button label="left">左浮</el-radio-button>
<el-radio-button label="right">右浮</el-radio-button>
</el-radio-group>
<el-switch v-else-if="column.rawColumnKey === 'hidden'" size=""
v-model="fields[$index][column.rawColumnKey]" inline-prompt :active-value="false"
active-text="显示" :inactive-value="true" inactive-text="隐藏" />
<el-input v-else size="" v-model="fields[$index][column.rawColumnKey]"></el-input>
</template>
</el-table-column>
</el-table>
<template #footer>
<el-link type="primary" class="mr-4" @click="addField">
<div class="i-ri-add-line"></div>
新增字段
</el-link>
<el-button @click="dialogVisible = false">取消</el-button>
<el-button :loading="loading" type="primary" @click="handlerSubmit">
提交
</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup>
const { updateFieldConfig } = useCloud()
const props = defineProps({
id: {
type: String,
default: ''
},
columns: {
type: Array,
default: () => []
}
})
const emits = defineEmits(['update:columns'])
const dialogVisible = ref(false)
const loading = ref(false)
const fields = ref([])
const columns = [
{ key: 'key', label: '字段' },
{ key: 'title', label: '名称' },
{ key: 'align', label: '对齐方式', width: 210 }, // 对齐方式
{ key: 'fixed', label: '固定列', width: 210 }, // 固定列
{ key: 'width', label: '列宽', width: 180 },
{ key: 'hidden', label: '显示', width: 80 }, // 隐藏
{ key: 'position', label: '', width: 200 },
{ key: 'remove', label: '', width: 42 },
]

// 打开弹窗
const handlerOpen = () => {
fields.value = JSON.parse(JSON.stringify(props.columns))
}

// 隐藏时,该行变淡
const handlerRowClass = ({ row }) => {
return row.hidden ? 'opacity-50' : ''
}

// 提交表单
const handlerSubmit = async () => {
loading.value = true
await updateFieldConfig(props.id, JSON.parse(JSON.stringify(fields.value)))
emits('update:columns', JSON.parse(JSON.stringify(fields.value)))
loading.value = false
dialogVisible.value = false
}

// 增加字段
const addField = () => {
fields.value.push({
key: '',
title: '',
width: 200
})
}

// 判断是否为新增字段, 新增字段可以编辑 key
const exitsCol = (key) => {
if (key === '') {
return false
}
return props.columns.find(item => item.key === key) ? true : false
}

// 移除字段
const handlerRemove = (index) => {
fields.value.splice(index, 1)
}

// 排序
const handlerSort = (action, index) => {
const handler = {
top: () => {
return 0
},
up: () => {
return index - 1
},
down: () => {
return index + 1
},
end: () => {
return fields.value.length - 1
}
}
let position = handler[action]()
const item = fields.value.splice(index, 1)[0]
fields.value.splice(position, 0, item)
}

// 排序按钮的禁用状态
const sortDisabled = (action, index) => {
if (index === 0 && ['top', 'up'].includes(action)) {
return true
}
if (index === fields.value.length - 1 && ['end', 'down'].includes(action)) {
return true
}

return false
}
</script>
41 changes: 33 additions & 8 deletions components/manager/header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: NMTuan
* @Email: NMTuan@qq.com
* @Date: 2023-07-13 09:34:02
* @LastEditTime: 2023-07-15 20:50:35
* @LastEditTime: 2023-08-13 12:23:14
* @LastEditors: NMTuan
* @Description:
* @FilePath: \laf_curd\components\manager\header.vue
Expand All @@ -13,10 +13,16 @@
<div class="flex items-center justify-center">
<div v-for="group in urls" class="ml-6 flex items-center">
[
<a :href="item.url" target="_blank" v-for="item in group" class="mx-2 flex items-center">
<img v-if="item.img" :src="item.img" />
<span v-else>{{ item.label }}</span>
</a>
<template v-for="item in group">
<span v-if="item.dialog" class="mx-2 cursor-pointer" hover="underline"
@click="handlerDialog(item.dialog)">
{{ item.label }}
</span>
<a v-else :href="item.url" target="_blank" class="mx-2 flex items-center">
<img v-if="item.img" :src="item.img" />
<span v-else>{{ item.label }}</span>
</a>
</template>
]
</div>
</div>
Expand All @@ -31,6 +37,16 @@
<div class="ml-4 flex-shrink-0">
<ManagerTab></ManagerTab>
</div>
<el-dialog v-model="sponsorVisible" title="Sponsor">
<div class="flex items-center justify-center overflow-hidden">
<div class="flex-1">
<img class="block w-full object-contain" src="@/assets/images/sponsor/wepay.jpg" alt="">
</div>
<div class="flex-1">
<img class="block w-full object-contain" src="@/assets/images/sponsor/alipay.jpg" alt="">
</div>
</div>
</el-dialog>
</div>
</template>
<script setup>
Expand All @@ -43,22 +59,25 @@ const urls = [

], [
{ label: 'Laf x DB', url: 'https://curd.muyi.dev/' },
{ label: 'Old', url: '/old/' },
// { label: 'Old', url: '/old/' },
{
label: 'GitHub', url: 'https://github.com/NMTuan/laf_curd',
img: 'https://img.shields.io/github/stars/NMTuan/laf_curd?style=flat-square&label=Github&labelColor=%2311a697&color=%2399f6e4'
},
{ label: 'Author', url: 'https://www.muyi.dev/' },
{ label: '🍗Sponsor', dialog: 'sponsor' },
], [
{ label: 'Laf x HeartBeat', url: 'https://heartbeat.muyi.dev/' },
]
]
const username = ref('')
const sponsorVisible = ref(false)

const fetchProfile = () => {
request({
path: '/v1/user/profile'
}).then(res => {
username.value = res.data.username || res.data.name
console.log('res', res)
// console.log('res', res)
})
.catch(() => { })
}
Expand All @@ -80,6 +99,12 @@ const handlerLogout = () => {

}

const handlerDialog = (type) => {
if (type === 'sponsor') {
sponsorVisible.value = true
}
}

fetchProfile()
</script>
<style lang="scss" scoped>
Expand Down
81 changes: 77 additions & 4 deletions composables/cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: NMTuan
* @Email: NMTuan@qq.com
* @Date: 2023-07-13 10:34:44
* @LastEditTime: 2023-07-15 18:22:39
* @LastEditTime: 2023-08-13 11:39:20
* @LastEditors: NMTuan
* @Description:
* @FilePath: \laf_curd\composables\cloud.js
Expand Down Expand Up @@ -112,8 +112,8 @@ export const useCloud = (payload) => {
}
payload = payload || {}
collection
.doc(id)
.update(payload)
.where({ _id: id })
.update(payload, { merge: false })
.then((res) => {
resolve(res)
})
Expand Down Expand Up @@ -240,15 +240,88 @@ export const useCloud = (payload) => {
})
}

// 获取字段配置
const getFieldConfig = () => {
return new Promise((resolve, reject) => {
cloud
.database()
.collection('lafDB_fields')
.where({
collectionName
})
.getOne()
.then((res) => {
resolve(res)
})
.catch((error) => {
reject(error)
})
})
}
const updateFieldConfig = (id, data) => {
return new Promise((resolve, reject) => {
if (!id) {
cloud
.database()
.collection('lafDB_fields')
.add({
collectionName,
columns: data
})
.then((res) => {
resolve(res)
})
.catch((err) => {
reject(err)
})
} else {
cloud
.database()
.collection('lafDB_fields')
.doc(id)
.update({
columns: data
})
.then((res) => {
resolve(res)
})
.catch((err) => {
reject(err)
})
}
})

// const id = data._id
// delete data._id
// return new Promise((resolve, reject) => {
// cloud
// .database()
// .collection('lafDB_fields')
// .doc(id)
// .update(data)
// .then((res) => {
// console.log('x', res)
// resolve(res)
// })
// .catch((error) => {
// reject(error)
// })
// })
}

return {
_,
collection,
collectionName,
cloud,
fetch,
count,
fetchOne,
update,
remove,
create,
run
run,
getFieldConfig,
updateFieldConfig
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
"@types/node": "^18",
"@unocss/nuxt": "^0.53.4",
"element-plus": "^2.3.7",
"nuxt": "^3.6.1",
"sass": "^1.63.6"
},
"dependencies": {
"@pinia/nuxt": "^0.4.11",
"ejson-shell-parser": "^1.2.4",
"laf-client-sdk": "^1.0.0-beta.8",
"nuxt": "^3.6.5",
"pinia": "^2.1.4",
"simplebar-vue": "^2.3.3"
}
Expand Down
Loading

0 comments on commit 1266ee9

Please sign in to comment.