commit
fbc90a4d1f
27 changed files with 1008 additions and 0 deletions
@ -0,0 +1,9 @@ |
|||||
|
root = true |
||||
|
|
||||
|
[*] |
||||
|
charset = utf-8 |
||||
|
indent_style = space |
||||
|
indent_size = 2 |
||||
|
end_of_line = lf |
||||
|
insert_final_newline = true |
||||
|
trim_trailing_whitespace = true |
@ -0,0 +1,5 @@ |
|||||
|
node_modules |
||||
|
dist |
||||
|
out |
||||
|
*.log* |
||||
|
package-lock.json |
@ -0,0 +1 @@ |
|||||
|
ELECTRON_MIRROR=https://npmmirror.com/mirrors/electron/ |
@ -0,0 +1,6 @@ |
|||||
|
out |
||||
|
dist |
||||
|
pnpm-lock.yaml |
||||
|
LICENSE.md |
||||
|
tsconfig.json |
||||
|
tsconfig.*.json |
@ -0,0 +1,6 @@ |
|||||
|
{ |
||||
|
"singleQuote": true, |
||||
|
"semi": false, |
||||
|
"printWidth": 100, |
||||
|
"trailingComma": "none" |
||||
|
} |
@ -0,0 +1,34 @@ |
|||||
|
# my-app |
||||
|
|
||||
|
An Electron application with Vue |
||||
|
|
||||
|
## Recommended IDE Setup |
||||
|
|
||||
|
- [VSCode](https://code.visualstudio.com/) + [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint) + [Prettier](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode) |
||||
|
|
||||
|
## Project Setup |
||||
|
|
||||
|
### Install(node 16.20.1) |
||||
|
|
||||
|
```bash |
||||
|
$ npm install |
||||
|
``` |
||||
|
|
||||
|
### Development |
||||
|
|
||||
|
```bash |
||||
|
$ npm run dev |
||||
|
``` |
||||
|
|
||||
|
### Build |
||||
|
|
||||
|
```bash |
||||
|
# For windows |
||||
|
$ npm run build:win |
||||
|
|
||||
|
# For macOS |
||||
|
$ npm run build:mac |
||||
|
|
||||
|
# For Linux |
||||
|
$ npm run build:linux |
||||
|
``` |
@ -0,0 +1,12 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
||||
|
<plist version="1.0"> |
||||
|
<dict> |
||||
|
<key>com.apple.security.cs.allow-jit</key> |
||||
|
<true/> |
||||
|
<key>com.apple.security.cs.allow-unsigned-executable-memory</key> |
||||
|
<true/> |
||||
|
<key>com.apple.security.cs.allow-dyld-environment-variables</key> |
||||
|
<true/> |
||||
|
</dict> |
||||
|
</plist> |
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
@ -0,0 +1,36 @@ |
|||||
|
const { notarize } = require('electron-notarize') |
||||
|
|
||||
|
module.exports = async (context) => { |
||||
|
if (process.platform !== 'darwin') return |
||||
|
|
||||
|
console.log('aftersign hook triggered, start to notarize app.') |
||||
|
|
||||
|
if (!process.env.CI) { |
||||
|
console.log(`skipping notarizing, not in CI.`) |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
if (!('APPLE_ID' in process.env && 'APPLE_ID_PASS' in process.env)) { |
||||
|
console.warn('skipping notarizing, APPLE_ID and APPLE_ID_PASS env variables must be set.') |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
const appId = 'com.electron.app' |
||||
|
|
||||
|
const { appOutDir } = context |
||||
|
|
||||
|
const appName = context.packager.appInfo.productFilename |
||||
|
|
||||
|
try { |
||||
|
await notarize({ |
||||
|
appBundleId: appId, |
||||
|
appPath: `${appOutDir}/${appName}.app`, |
||||
|
appleId: process.env.APPLE_ID, |
||||
|
appleIdPassword: process.env.APPLEIDPASS |
||||
|
}) |
||||
|
} catch (error) { |
||||
|
console.error(error) |
||||
|
} |
||||
|
|
||||
|
console.log(`done notarizing ${appId}.`) |
||||
|
} |
@ -0,0 +1,43 @@ |
|||||
|
appId: com.electron.lichong |
||||
|
productName: 桌面应用 |
||||
|
directories: |
||||
|
buildResources: build |
||||
|
files: |
||||
|
- '!**/.vscode/*' |
||||
|
- '!src/*' |
||||
|
- '!electron.vite.config.{js,ts,mjs,cjs}' |
||||
|
- '!{.eslintignore,.eslintrc.cjs,.prettierignore,.prettierrc.yaml,dev-app-update.yml,CHANGELOG.md,README.md}' |
||||
|
asarUnpack: |
||||
|
- '**/*.{node,dll}' |
||||
|
afterSign: build/notarize.js |
||||
|
win: |
||||
|
executableName: lichong-app |
||||
|
nsis: |
||||
|
oneClick: false |
||||
|
artifactName: 处方统计-${version}-setup.${ext} |
||||
|
allowToChangeInstallationDirectory: true |
||||
|
shortcutName: ${productName} |
||||
|
uninstallDisplayName: ${productName} |
||||
|
createDesktopShortcut: always |
||||
|
mac: |
||||
|
entitlementsInherit: build/entitlements.mac.plist |
||||
|
extendInfo: |
||||
|
- NSCameraUsageDescription: Application requests access to the device's camera. |
||||
|
- NSMicrophoneUsageDescription: Application requests access to the device's microphone. |
||||
|
- NSDocumentsFolderUsageDescription: Application requests access to the user's Documents folder. |
||||
|
- NSDownloadsFolderUsageDescription: Application requests access to the user's Downloads folder. |
||||
|
dmg: |
||||
|
artifactName: ${name}-${version}.${ext} |
||||
|
linux: |
||||
|
target: |
||||
|
- AppImage |
||||
|
- snap |
||||
|
- deb |
||||
|
maintainer: electronjs.org |
||||
|
category: Utility |
||||
|
appImage: |
||||
|
artifactName: ${name}-${version}.${ext} |
||||
|
npmRebuild: false |
||||
|
publish: |
||||
|
provider: generic |
||||
|
url: https://example.com/auto-updates |
@ -0,0 +1,28 @@ |
|||||
|
import { resolve } from 'path' |
||||
|
import { defineConfig, externalizeDepsPlugin } from 'electron-vite' |
||||
|
import vue from '@vitejs/plugin-vue' |
||||
|
|
||||
|
export default defineConfig({ |
||||
|
main: { |
||||
|
plugins: [externalizeDepsPlugin()] |
||||
|
}, |
||||
|
preload: { |
||||
|
plugins: [externalizeDepsPlugin()], |
||||
|
build: { |
||||
|
rollupOptions: { |
||||
|
input: { |
||||
|
dl: resolve(__dirname, 'src/preload/dl.js'), |
||||
|
index: resolve(__dirname, 'src/preload/index.js') |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
renderer: { |
||||
|
resolve: { |
||||
|
alias: { |
||||
|
'@renderer': resolve('src/renderer/src') |
||||
|
} |
||||
|
}, |
||||
|
plugins: [vue()] |
||||
|
} |
||||
|
}) |
@ -0,0 +1,6 @@ |
|||||
|
{ |
||||
|
"exclude": [ |
||||
|
"node_modules", |
||||
|
"public" |
||||
|
] |
||||
|
} |
@ -0,0 +1,38 @@ |
|||||
|
{ |
||||
|
"name": "electron", |
||||
|
"version": "1.0.0", |
||||
|
"description": "An Electron application with Vue", |
||||
|
"main": "./out/main/index.js", |
||||
|
"author": "lichong", |
||||
|
"homepage": "https://www.electronjs.org", |
||||
|
"scripts": { |
||||
|
"npmi": "npm i", |
||||
|
"dev": "electron-vite dev", |
||||
|
"build": "electron-vite build", |
||||
|
"build:win": "npm run build && electron-builder --win --config", |
||||
|
"build:mac": "npm run build && electron-builder --mac --config", |
||||
|
"build:linux": "npm run build && electron-builder --linux --config" |
||||
|
}, |
||||
|
"dependencies": { |
||||
|
"@electron-toolkit/preload": "^1.0.2", |
||||
|
"@electron-toolkit/utils": "^1.0.2", |
||||
|
"dayjs": "^1.11.11", |
||||
|
"dexie": "^4.0.8", |
||||
|
"element-plus": "^2.7.1", |
||||
|
"lodash": "^4.17.21", |
||||
|
"vxe-table": "^4.7.87" |
||||
|
}, |
||||
|
"devDependencies": { |
||||
|
"@rushstack/eslint-patch": "^1.2.0", |
||||
|
"@vitejs/plugin-vue": "^3.1.2", |
||||
|
"@vue/eslint-config-prettier": "^7.0.0", |
||||
|
"electron": "^20.3.2", |
||||
|
"electron-builder": "^23.6.0", |
||||
|
"electron-notarize": "^1.2.1", |
||||
|
"electron-vite": "^1.0.11", |
||||
|
"less": "^4.1.3", |
||||
|
"prettier": "^2.7.1", |
||||
|
"vite": "^3.1.8", |
||||
|
"vue": "^3.2.41" |
||||
|
} |
||||
|
} |
After Width: | Height: | Size: 16 KiB |
@ -0,0 +1,68 @@ |
|||||
|
import { app, shell, BrowserWindow, nativeImage, ipcMain } from 'electron' |
||||
|
import * as path from 'path' |
||||
|
import { electronApp, optimizer, is } from '@electron-toolkit/utils' |
||||
|
|
||||
|
// logo
|
||||
|
const logoIcon = nativeImage.createFromPath(path.join(__dirname, '../../public/icon/icon.jpg')) |
||||
|
// 主窗口
|
||||
|
let mainWindow |
||||
|
function createWindow() { |
||||
|
mainWindow = new BrowserWindow({ |
||||
|
minWidth: 1366, |
||||
|
minHeight: 900, |
||||
|
height: 1260, |
||||
|
show: false, |
||||
|
autoHideMenuBar: true, |
||||
|
icon: logoIcon, |
||||
|
webPreferences: { |
||||
|
preload: path.resolve(__dirname, '../preload/index.js'), |
||||
|
sandbox: false |
||||
|
} |
||||
|
}) |
||||
|
mainWindow.on('ready-to-show', () => { |
||||
|
mainWindow.show() |
||||
|
// mainWindow.webContents.openDevTools()
|
||||
|
}) |
||||
|
mainWindow.webContents.setWindowOpenHandler((details) => { |
||||
|
shell.openExternal(details.url) |
||||
|
return { action: 'deny' } |
||||
|
}) |
||||
|
// mainWindow.loadURL('http://localhost:5173/')
|
||||
|
|
||||
|
mainWindow.on('close', () => { |
||||
|
app.exit() |
||||
|
}) |
||||
|
if (is.dev && process.env['ELECTRON_RENDERER_URL']) { |
||||
|
mainWindow.loadURL(process.env['ELECTRON_RENDERER_URL']) |
||||
|
} else { |
||||
|
mainWindow.loadFile(path.join(__dirname, '../renderer/index.html')) |
||||
|
} |
||||
|
} |
||||
|
app.whenReady().then(() => { |
||||
|
electronApp.setAppUserModelId('com.electron') |
||||
|
// Default open or close DevTools by F12 in development
|
||||
|
// and ignore CommandOrControl + R in production.
|
||||
|
// see https://github.com/alex8088/electron-toolkit/tree/master/packages/utils
|
||||
|
app.on('browser-window-created', (_, window) => { |
||||
|
optimizer.watchWindowShortcuts(window) |
||||
|
}) |
||||
|
|
||||
|
createWindow() |
||||
|
|
||||
|
app.on('activate', function () { |
||||
|
// On macOS it's common to re-create a window in the app when the
|
||||
|
// dock icon is clicked and there are no other windows open.
|
||||
|
if (BrowserWindow.getAllWindows().length === 0) createWindow() |
||||
|
}) |
||||
|
}) |
||||
|
app.commandLine.appendSwitch('autoplay-policy', 'no-user-gesture-required'); |
||||
|
// Quit when all windows are closed, except on macOS. There, it's common
|
||||
|
// for applications and their menu bar to stay active until the user quits
|
||||
|
// explicitly with Cmd + Q.
|
||||
|
app.on('window-all-closed', () => { |
||||
|
if (process.platform !== 'darwin') { |
||||
|
app.quit() |
||||
|
} |
||||
|
}) |
||||
|
// In this file you can include the rest of your app"s specific main process
|
||||
|
// code. You can also put them in separate files and require them here.
|
@ -0,0 +1,21 @@ |
|||||
|
import { contextBridge, clipboard } from 'electron' |
||||
|
import { electronAPI } from '@electron-toolkit/preload' |
||||
|
|
||||
|
// Custom APIs for renderer
|
||||
|
const api = {} |
||||
|
|
||||
|
// Use `contextBridge` APIs to expose Electron APIs to
|
||||
|
// renderer only if context isolation is enabled, otherwise
|
||||
|
// just add to the DOM global.
|
||||
|
if (process.contextIsolated) { |
||||
|
try { |
||||
|
contextBridge.exposeInMainWorld('electron', electronAPI) |
||||
|
contextBridge.exposeInMainWorld('api', api) |
||||
|
contextBridge.exposeInMainWorld('elecClipboard', clipboard) |
||||
|
} catch (error) { |
||||
|
console.error(error) |
||||
|
} |
||||
|
} else { |
||||
|
window.electron = electronAPI |
||||
|
window.api = api |
||||
|
} |
@ -0,0 +1,21 @@ |
|||||
|
import { contextBridge, clipboard } from 'electron' |
||||
|
import { electronAPI } from '@electron-toolkit/preload' |
||||
|
|
||||
|
// Custom APIs for renderer
|
||||
|
const api = {} |
||||
|
|
||||
|
// Use `contextBridge` APIs to expose Electron APIs to
|
||||
|
// renderer only if context isolation is enabled, otherwise
|
||||
|
// just add to the DOM global.
|
||||
|
if (process.contextIsolated) { |
||||
|
try { |
||||
|
contextBridge.exposeInMainWorld('electron', electronAPI) |
||||
|
contextBridge.exposeInMainWorld('api', api) |
||||
|
contextBridge.exposeInMainWorld('elecClipboard', clipboard) |
||||
|
} catch (error) { |
||||
|
console.error(error) |
||||
|
} |
||||
|
} else { |
||||
|
window.electron = electronAPI |
||||
|
window.api = api |
||||
|
} |
@ -0,0 +1,18 @@ |
|||||
|
<!DOCTYPE html> |
||||
|
<html> |
||||
|
|
||||
|
<head> |
||||
|
<meta charset="UTF-8" /> |
||||
|
<title>处方统计</title> |
||||
|
<!-- <link rel="icon" href="/icon/icon.jpg" /> --> |
||||
|
<!-- https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP --> |
||||
|
<meta http-equiv="Content-Security-Policy" |
||||
|
content="default-src 'self'; script-src 'self';img-src 'self' data:; style-src 'self' 'unsafe-inline';font-src 'self' data:;" /> |
||||
|
</head> |
||||
|
|
||||
|
<body> |
||||
|
<div id="app"></div> |
||||
|
<script type="module" src="/src/main.js"></script> |
||||
|
</body> |
||||
|
|
||||
|
</html> |
@ -0,0 +1,65 @@ |
|||||
|
<template> |
||||
|
<div class="appClass" v-if="isVip"> |
||||
|
<chufangComponent ref="chufang"> </chufangComponent> |
||||
|
</div> |
||||
|
<div v-else class="noVip"> |
||||
|
<h3> |
||||
|
<el-tag type="danger" class="noVipTag">体验已过期,请联系管理员。</el-tag> |
||||
|
</h3> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import _ from 'lodash' |
||||
|
import dayjs from 'dayjs' |
||||
|
import { myDatabase } from './assets/js/db.js' |
||||
|
import chufangComponent from "./views/chufang.vue" |
||||
|
import { ElMessage } from 'element-plus'; |
||||
|
export default { |
||||
|
name: 'app', |
||||
|
components: { chufangComponent }, |
||||
|
data() { |
||||
|
return { |
||||
|
_: _, |
||||
|
dayjs: dayjs, |
||||
|
isVip: false, |
||||
|
jihuoma: "", |
||||
|
zhucema: "", |
||||
|
} |
||||
|
}, |
||||
|
watch: {}, |
||||
|
computed: {}, |
||||
|
methods: { |
||||
|
}, |
||||
|
async mounted() { |
||||
|
let fiveDay = dayjs('2024-11-7T00:00:00').valueOf() |
||||
|
if (!this.isVip) { |
||||
|
if (dayjs().valueOf() > fiveDay) { |
||||
|
this.isVip = false |
||||
|
return |
||||
|
} else { |
||||
|
this.isVip = true |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
} |
||||
|
</script> |
||||
|
<style scoped> |
||||
|
.appClass { |
||||
|
width: 100vw; |
||||
|
height: 100vh; |
||||
|
position: relative; |
||||
|
} |
||||
|
|
||||
|
.noVip { |
||||
|
text-align: center; |
||||
|
margin-top: calc(50vh - 98px); |
||||
|
} |
||||
|
|
||||
|
.noVipTag { |
||||
|
font-size: 48px; |
||||
|
line-height: 48px; |
||||
|
padding: 36px; |
||||
|
} |
||||
|
</style> |
@ -0,0 +1,13 @@ |
|||||
|
html, |
||||
|
body { |
||||
|
margin: 0; |
||||
|
padding: 0; |
||||
|
} |
||||
|
|
||||
|
.red { |
||||
|
color: #f56c6c; |
||||
|
} |
||||
|
|
||||
|
.blue { |
||||
|
color: #409eff; |
||||
|
} |
@ -0,0 +1,8 @@ |
|||||
|
import Dexie from 'dexie'; |
||||
|
|
||||
|
export const myDatabase = new Dexie('myDatabase'); |
||||
|
|
||||
|
// 定义数据库版本
|
||||
|
myDatabase.version(1).stores({ |
||||
|
chufang: '++id, xingming, chufang, shetai, create_at, update_at', |
||||
|
}); |
@ -0,0 +1,42 @@ |
|||||
|
[ |
||||
|
{ |
||||
|
"label": "姓名", |
||||
|
"prop": "xingming", |
||||
|
"type": "text", |
||||
|
"isSort": false, |
||||
|
"tableShow": true, |
||||
|
"formShow": true |
||||
|
}, |
||||
|
{ |
||||
|
"label": "处方照片", |
||||
|
"prop": "chufang", |
||||
|
"type": "photo", |
||||
|
"isSort": false, |
||||
|
"tableShow": true, |
||||
|
"formShow": true |
||||
|
}, |
||||
|
{ |
||||
|
"label": "舌苔照片", |
||||
|
"prop": "shetai", |
||||
|
"type": "photo", |
||||
|
"isSort": false, |
||||
|
"tableShow": true, |
||||
|
"formShow": true |
||||
|
}, |
||||
|
{ |
||||
|
"label": "创建时间", |
||||
|
"prop": "create_at", |
||||
|
"type": "date", |
||||
|
"isSort": true, |
||||
|
"tableShow": true, |
||||
|
"formShow": false |
||||
|
}, |
||||
|
{ |
||||
|
"label": "更新时间", |
||||
|
"prop": "update_at", |
||||
|
"type": "date", |
||||
|
"isSort": false, |
||||
|
"tableShow": false, |
||||
|
"formShow": false |
||||
|
} |
||||
|
] |
@ -0,0 +1,72 @@ |
|||||
|
<template> |
||||
|
<div class="tableClass"> |
||||
|
<el-form :model="formData" label-suffix=":" :disabled="disabled" inline> |
||||
|
<el-form-item :label="formItem.label" :key="formIndex" v-for="(formItem, formIndex) in formHeader"> |
||||
|
<template v-if="formItem.type === 'text'"> |
||||
|
<el-input v-model="formData[formItem.prop]" /> |
||||
|
</template> |
||||
|
<template v-else-if="formItem.type === 'date'"> |
||||
|
<el-date-picker v-model="formData[formItem.prop]" type="date" |
||||
|
:disabled="['create_at', 'update_at'].indexOf(formItem.prop) !== -1" |
||||
|
:placeholder="`请选择${formItem.label}`" /> |
||||
|
</template> |
||||
|
<template v-else-if="formItem.type === 'photo'"> |
||||
|
<div class="camera-capture"> |
||||
|
<video :ref="`${formItem.prop}vedio`" autoplay playsinline></video> |
||||
|
<button @click="takePhoto(formItem)">拍照</button> |
||||
|
<canvas :ref="`${formItem.prop}canvas`" style="display: none;"></canvas> |
||||
|
<img v-if="formData[formItem.prop]" :src="formData[formItem.prop]" alt="Captured Photo" /> |
||||
|
</div> |
||||
|
</template> |
||||
|
</el-form-item> |
||||
|
</el-form> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import _, { max, min } from 'lodash' |
||||
|
import dayjs from 'dayjs' |
||||
|
import { ElMessage, ElMessageBox } from 'element-plus' |
||||
|
export default { |
||||
|
name: 'formcomponent', |
||||
|
components: {}, |
||||
|
props: { |
||||
|
formHeader: { |
||||
|
type: Array, |
||||
|
default: () => { |
||||
|
return [] |
||||
|
} |
||||
|
}, |
||||
|
formData: { |
||||
|
type: Object, |
||||
|
default: () => { |
||||
|
return {} |
||||
|
} |
||||
|
}, |
||||
|
disabled: { |
||||
|
type: Boolean, |
||||
|
default: () => { |
||||
|
return false |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
}, |
||||
|
data() { |
||||
|
return { |
||||
|
_: _, |
||||
|
dayjs: dayjs, |
||||
|
|
||||
|
} |
||||
|
}, |
||||
|
methods: {}, |
||||
|
async mounted() { }, |
||||
|
watch: {}, |
||||
|
computed: {} |
||||
|
} |
||||
|
</script> |
||||
|
<style scoped> |
||||
|
.tableClass { |
||||
|
text-align: left; |
||||
|
text-align-last: left; |
||||
|
} |
||||
|
</style> |
@ -0,0 +1,130 @@ |
|||||
|
<template> |
||||
|
<div class="tableClass"> |
||||
|
<el-auto-resizer> |
||||
|
<template #default="{ height, width }"> |
||||
|
<vxe-table show-overflow :data="tableData" round :height="height" :scroll-y="{ enabled: true, gt: 20 }" |
||||
|
:checkbox-config="{ labelField: 'seq', highlight: true }" @checkbox-all="selectAllChangeEvent" |
||||
|
@checkbox-change="selectChange" ref="tableRef" border :column-config="{ resizable: true }"> |
||||
|
<vxe-column type="seq" width="70"></vxe-column> |
||||
|
<vxe-column type="checkbox" width="70" fixed="left"></vxe-column> |
||||
|
<vxe-column :field="headerItem.prop" :title="headerItem.label" |
||||
|
:min-width="`${headerItem.label.length * 23 + 24}`" v-for="(headerItem, headerIndex) in tableHeader" |
||||
|
:key="headerIndex" :sortable="headerItem.isSort"> |
||||
|
<template #default="{ row }"> |
||||
|
<template v-if="headerItem.type === 'text'"> |
||||
|
<span>{{ row[headerItem.prop] }}</span> |
||||
|
</template> |
||||
|
<template v-else-if="headerItem.type === 'date'"> |
||||
|
<span>{{ row[headerItem.prop] }}</span> |
||||
|
</template> |
||||
|
<template v-else-if="headerItem.type === 'photo'"> |
||||
|
<el-image style="width: 100px; height: 100px" :src="row[headerItem.prop]" :zoom-rate="1.2" |
||||
|
:max-scale="7" :min-scale="0.2" :preview-src-list="[row[headerItem.prop]]" :initial-index="4" |
||||
|
fit="cover" /> |
||||
|
{{ row[headerItem.prop] }}</template> |
||||
|
<template v-else>{{ row[headerItem.prop] }}</template> |
||||
|
</template> |
||||
|
</vxe-column> |
||||
|
<vxe-column fixed="right" title="操作" width="145"> |
||||
|
<template #default="{ row }"> |
||||
|
<el-button type="primary" circle @click="optClick(row, 'edit')"> |
||||
|
<el-icon> |
||||
|
<Edit /> |
||||
|
</el-icon> |
||||
|
</el-button> |
||||
|
<el-button type="info" circle @click="optClick(row, 'info')"> |
||||
|
<el-icon> |
||||
|
<InfoFilled /> |
||||
|
</el-icon> |
||||
|
</el-button> |
||||
|
<el-button type="danger" circle @click="optClick(row, 'del')"> |
||||
|
<el-icon> |
||||
|
<Delete /> |
||||
|
</el-icon> |
||||
|
</el-button> |
||||
|
</template> |
||||
|
</vxe-column> |
||||
|
</vxe-table> |
||||
|
</template> |
||||
|
</el-auto-resizer> |
||||
|
|
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import _ from 'lodash' |
||||
|
import dayjs from 'dayjs' |
||||
|
import { ElMessage, ElMessageBox } from 'element-plus' |
||||
|
export default { |
||||
|
name: 'tablecomponent', |
||||
|
components: {}, |
||||
|
emits: ["selectChange", "edit", "info", "del", "headerSort"], |
||||
|
props: { |
||||
|
tableHeader: { |
||||
|
type: Array, |
||||
|
default: () => { |
||||
|
return [] |
||||
|
} |
||||
|
}, |
||||
|
tableData: { |
||||
|
type: Array, |
||||
|
default: () => { |
||||
|
return [] |
||||
|
} |
||||
|
}, |
||||
|
}, |
||||
|
data() { |
||||
|
return { |
||||
|
_: _, |
||||
|
dayjs: dayjs, |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
selectChange({ checked }) { |
||||
|
let $table = this.$refs.tableRef |
||||
|
if ($table) { |
||||
|
let selection = $table.getCheckboxRecords() |
||||
|
this.$emit("selectChange", selection) |
||||
|
} |
||||
|
}, |
||||
|
selectAllChangeEvent({ checked }) { |
||||
|
let $table = this.$refs.tableRef |
||||
|
if ($table) { |
||||
|
let selection = $table.getCheckboxRecords() |
||||
|
this.$emit("selectChange", selection) |
||||
|
} |
||||
|
}, |
||||
|
optClick(row, type) { |
||||
|
this.$emit(type, row) |
||||
|
}, |
||||
|
headerSort(headerItem) { |
||||
|
for (let i = 0; i < this.tableHeader.length; i++) { |
||||
|
let item = this.tableHeader[i]; |
||||
|
if (headerItem.prop !== item.prop) { |
||||
|
item.sort = "" |
||||
|
} |
||||
|
} |
||||
|
let sortOld = headerItem.sort |
||||
|
if (sortOld === "") { |
||||
|
headerItem.sort = 1 |
||||
|
} else if (sortOld === 1) { |
||||
|
headerItem.sort = -1 |
||||
|
} else if (sortOld === -1) { |
||||
|
headerItem.sort = "" |
||||
|
} |
||||
|
|
||||
|
this.$emit("headerSort", headerItem) |
||||
|
}, |
||||
|
}, |
||||
|
async mounted() { }, |
||||
|
watch: {}, |
||||
|
computed: {} |
||||
|
} |
||||
|
</script> |
||||
|
<style scoped> |
||||
|
.tableClass { |
||||
|
height: calc(100vh - 70px); |
||||
|
text-align: center; |
||||
|
text-align-last: center; |
||||
|
} |
||||
|
</style> |
@ -0,0 +1,33 @@ |
|||||
|
// main.ts
|
||||
|
import { createApp } from 'vue' |
||||
|
import ElementPlus from 'element-plus' |
||||
|
import zhCn from 'element-plus/es/locale/lang/zh-cn' |
||||
|
import 'element-plus/dist/index.css' |
||||
|
import App from './App.vue' |
||||
|
import './assets/css/base.css' |
||||
|
import * as ElementPlusIconsVue from '@element-plus/icons-vue' |
||||
|
import VxeUI from 'vxe-pc-ui' |
||||
|
import 'vxe-pc-ui/lib/style.css' |
||||
|
// ...
|
||||
|
|
||||
|
// 完整导入 表格库
|
||||
|
import VxeUITable from 'vxe-table' |
||||
|
import 'vxe-table/lib/style.css' |
||||
|
|
||||
|
const app = createApp(App) |
||||
|
// window.__VUE_PROD_HYDRATION_MISMATCH_DETAILS__ = true
|
||||
|
for (const [key, component] of Object.entries(ElementPlusIconsVue)) { |
||||
|
app.component(key, component) |
||||
|
} |
||||
|
app.use(ElementPlus, { |
||||
|
locale: zhCn, |
||||
|
}) |
||||
|
app.use(VxeUI).use(VxeUITable) |
||||
|
app.mount('#app') |
||||
|
|
||||
|
document.addEventListener('keydown', (event) => { |
||||
|
const { ctrlKey, shiftKey, key } = event |
||||
|
if ((ctrlKey && shiftKey && key === 'I') || key === 'F12') { |
||||
|
return event.preventDefault() |
||||
|
} |
||||
|
}) |
@ -0,0 +1,293 @@ |
|||||
|
<template> |
||||
|
<div class="rightClass"> |
||||
|
<div> |
||||
|
<el-row style="margin-bottom: 8px;"> |
||||
|
<el-col :span="16"> |
||||
|
<el-button type="primary" @click="addData" size="large"> |
||||
|
<el-icon> |
||||
|
<Plus /> |
||||
|
</el-icon> |
||||
|
<span>新增</span> |
||||
|
</el-button> |
||||
|
<el-button type="danger" @click="deleteData(selectionData)" :disabled="selectionData.length == 0" |
||||
|
size="large"> |
||||
|
<el-icon> |
||||
|
<Delete /> |
||||
|
</el-icon> |
||||
|
<span>删除</span> |
||||
|
</el-button> |
||||
|
<el-button type="danger" @click="delAll" size="large"> |
||||
|
<el-icon> |
||||
|
<Delete /> |
||||
|
</el-icon> |
||||
|
<span>清空</span> |
||||
|
</el-button> |
||||
|
</el-col> |
||||
|
<el-col :span="6"> |
||||
|
<el-input v-model="searchParams.xingming" placeholder="请输入输入姓名" size="large"> |
||||
|
<template #append> |
||||
|
<el-button type="primary" @click="updateSeach()" size="large"> |
||||
|
<el-icon> |
||||
|
<Search /> |
||||
|
</el-icon> |
||||
|
<span>搜索</span> |
||||
|
</el-button> |
||||
|
</template> |
||||
|
</el-input> |
||||
|
</el-col> |
||||
|
</el-row> |
||||
|
</div> |
||||
|
<div v-loading="loading"> |
||||
|
<tablecomponent :tableHeader="tableHeader" :tableData="tableData" @selectChange="selectChange" @edit="edit" |
||||
|
@info="info" @del="del" ref="tableComponentRef" @headerSort="headerSort"> |
||||
|
</tablecomponent> |
||||
|
</div> |
||||
|
<el-dialog v-model="dialogFrom.visible" :title="dialogFrom.title" width="80%"> |
||||
|
<formcomponent :formHeader="dialogFrom.formHeader" :formData="dialogFrom.formData" |
||||
|
:disabled="dialogFrom.disabled"> |
||||
|
</formcomponent> |
||||
|
<template #footer> |
||||
|
<div> |
||||
|
<el-button @click="cancelDialog">取消</el-button> |
||||
|
<el-button type="primary" @click="submitDialog"> 确认 </el-button> |
||||
|
</div> |
||||
|
</template> |
||||
|
</el-dialog> |
||||
|
</div> |
||||
|
</template> |
||||
|
|
||||
|
<script> |
||||
|
import _ from 'lodash' |
||||
|
import tableHeaderLocal from '../assets/json/chufang.json' |
||||
|
import { myDatabase } from '../assets/js/db.js' |
||||
|
import dayjs from 'dayjs' |
||||
|
import tablecomponent from "../components/tablecomponent.vue" |
||||
|
import formcomponent from "../components/formcomponent.vue" |
||||
|
import { ElMessage, ElMessageBox } from 'element-plus' |
||||
|
export default { |
||||
|
name: 'chufang', |
||||
|
components: { tablecomponent, formcomponent }, |
||||
|
watch: {}, |
||||
|
computed: {}, |
||||
|
data() { |
||||
|
return { |
||||
|
_: _, |
||||
|
dayjs: dayjs, |
||||
|
tableHeader: [], |
||||
|
formHeader: [], |
||||
|
tableData: [], |
||||
|
searchParams: { |
||||
|
xingming: "" |
||||
|
}, |
||||
|
selectionData: [], |
||||
|
dialogFrom: { |
||||
|
visible: false, |
||||
|
title: "新增处方", |
||||
|
type: "add", |
||||
|
formHeader: [], |
||||
|
formData: {} |
||||
|
}, |
||||
|
sortObj: {}, |
||||
|
loading: false, |
||||
|
} |
||||
|
}, |
||||
|
methods: { |
||||
|
//更新数据 |
||||
|
async updateSeach() { |
||||
|
this.loading = true |
||||
|
let allChufangList = _.cloneDeep(await myDatabase.chufang.toArray()) |
||||
|
let dataTemp = [] |
||||
|
if (_.trim(this.searchParams.xingming)) { |
||||
|
for (let i = 0; i < allChufangList.length; i++) { |
||||
|
let element = allChufangList[i]; |
||||
|
if (element.xingming.includes(_.trim(this.searchParams.xingming))) { |
||||
|
dataTemp.push({ ...element }) |
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
dataTemp = _.cloneDeep(allChufangList) |
||||
|
} |
||||
|
let dataTempSort = dataTemp |
||||
|
if (_.get(this.sortObj, ["sort"], "")) { |
||||
|
// 带条件排序 |
||||
|
dataTempSort = _.orderBy(dataTemp, [this.sortObj.prop], [_.get(this.sortObj, ["sort"], "") === 1 ? 'desc' : 'asc']) |
||||
|
} |
||||
|
this.tableData = _.uniqBy(dataTempSort, "id") |
||||
|
this.loading = false |
||||
|
}, |
||||
|
// 排序 |
||||
|
async headerSort(headerSort) { |
||||
|
this.sortObj = headerSort |
||||
|
await this.updateSeach() |
||||
|
}, |
||||
|
//选中数据 |
||||
|
selectChange(selection) { |
||||
|
this.selectionData = _.cloneDeep(selection) |
||||
|
}, |
||||
|
//关闭模态框 |
||||
|
cancelDialog() { |
||||
|
this.dialogFrom = { |
||||
|
visible: false, |
||||
|
title: "新增", |
||||
|
type: "add", |
||||
|
formHeader: [], |
||||
|
formData: {} |
||||
|
} |
||||
|
}, |
||||
|
//确认模态框 |
||||
|
async submitDialog() { |
||||
|
for (let i = 0; i < this.formHeader.length; i++) { |
||||
|
let headItem = this.formHeader[i]; |
||||
|
if (headItem.type === "date") { |
||||
|
this.dialogFrom.formData[headItem.prop] = dayjs(this.dialogFrom.formData[headItem.prop]).format("YYYY-MM-DD") |
||||
|
} |
||||
|
} |
||||
|
let params = { |
||||
|
...this.dialogFrom.formData, ...this.dealRow(this.dialogFrom.formData), create_at: dayjs().format('YYYY-MM-DD HH:mm:ss'), update_at: dayjs().format('YYYY-MM-DD HH:mm:ss') |
||||
|
} |
||||
|
if (this.dialogFrom.type === "put") { |
||||
|
delete params.create_at |
||||
|
} |
||||
|
try { |
||||
|
await myDatabase.chufang[this.dialogFrom.type]({ ...params, update_at: dayjs().format('YYYY-MM-DD HH:mm:ss') }) |
||||
|
await this.updateSeach() |
||||
|
this.cancelDialog() |
||||
|
} catch (e) { |
||||
|
ElMessage( |
||||
|
{ |
||||
|
type: "error", |
||||
|
message: "时间不允许重复,请重新设置时间" |
||||
|
} |
||||
|
) |
||||
|
} |
||||
|
}, |
||||
|
//打开新增模态框 |
||||
|
addData() { |
||||
|
let formData = {} |
||||
|
for (let i = 0; i < this.formHeader.length; i++) { |
||||
|
let element = this.formHeader[i]; |
||||
|
if (element.type === "text") { |
||||
|
formData[element.prop] = "" |
||||
|
} else if (element.type === "date") { |
||||
|
formData[element.prop] = dayjs().subtract(element.default || 0, 'year').format("YYYY-MM-DD") |
||||
|
} |
||||
|
} |
||||
|
this.dialogFrom = { |
||||
|
visible: true, |
||||
|
title: "新增", |
||||
|
type: "add", |
||||
|
disabled: false, |
||||
|
formHeader: this.formHeader, |
||||
|
formData |
||||
|
} |
||||
|
}, |
||||
|
//打开编辑数据模态框 |
||||
|
edit(row) { |
||||
|
this.dialogFrom = { |
||||
|
visible: true, |
||||
|
title: `编辑${row.xingming}`, |
||||
|
type: "put", |
||||
|
disabled: false, |
||||
|
formHeader: this.formHeader, |
||||
|
formData: { ...row } |
||||
|
} |
||||
|
}, |
||||
|
//打开查看数据模态框 |
||||
|
info(row) { |
||||
|
this.dialogFrom = { |
||||
|
visible: true, |
||||
|
title: `查看${row.xingming}`, |
||||
|
type: "info", |
||||
|
disabled: true, |
||||
|
formHeader: this.formHeader, |
||||
|
formData: { ...row } |
||||
|
} |
||||
|
}, |
||||
|
//删除数据 |
||||
|
del(row) { |
||||
|
this.deleteData([row]) |
||||
|
}, |
||||
|
//批量删除数据 |
||||
|
deleteData(delList) { |
||||
|
let tooltipList = [] |
||||
|
let idList = [] |
||||
|
for (let i = 0; i < delList.length; i++) { |
||||
|
let element = delList[i]; |
||||
|
tooltipList.push(element.xingming) |
||||
|
idList.push(element.id) |
||||
|
} |
||||
|
ElMessageBox.confirm( |
||||
|
`是否删除(${_.join(tooltipList, ",")})?`, |
||||
|
'danger', |
||||
|
{ |
||||
|
confirmButtonText: '确认', |
||||
|
cancelButtonText: '取消', |
||||
|
type: 'danger', |
||||
|
} |
||||
|
) |
||||
|
.then(async () => { |
||||
|
this.$refs.tableComponentRef.clearSelection() |
||||
|
await myDatabase.chufang.bulkDelete(idList) |
||||
|
await this.updateSeach() |
||||
|
}) |
||||
|
.catch(() => { |
||||
|
ElMessage({ |
||||
|
type: 'info', |
||||
|
message: '取消删除', |
||||
|
}) |
||||
|
}) |
||||
|
|
||||
|
}, |
||||
|
//删除全部数据 |
||||
|
delAll() { |
||||
|
ElMessageBox.confirm( |
||||
|
`是否删除全部数据?此操作不可逆!`, |
||||
|
'危险操作', |
||||
|
{ |
||||
|
confirmButtonText: '确认', |
||||
|
cancelButtonText: '取消', |
||||
|
type: 'danger', |
||||
|
} |
||||
|
) |
||||
|
.then(async () => { |
||||
|
this.$refs.tableComponentRef.clearSelection() |
||||
|
await myDatabase.chufang.clear() |
||||
|
await this.updateSeach() |
||||
|
}) |
||||
|
.catch(() => { |
||||
|
ElMessage({ |
||||
|
type: 'info', |
||||
|
message: '取消删除', |
||||
|
}) |
||||
|
}) |
||||
|
}, |
||||
|
}, |
||||
|
async mounted() { |
||||
|
this.tableHeader = _.filter(tableHeaderLocal, o => o.tableShow) |
||||
|
this.formHeader = _.filter(tableHeaderLocal, o => o.formShow) |
||||
|
await this.updateSeach() |
||||
|
}, |
||||
|
} |
||||
|
</script> |
||||
|
<style scoped> |
||||
|
.rightClass { |
||||
|
padding: 8px; |
||||
|
} |
||||
|
|
||||
|
.uploadClass { |
||||
|
top: 3px; |
||||
|
} |
||||
|
|
||||
|
.inputClass { |
||||
|
display: inline-block; |
||||
|
margin: 0 8px; |
||||
|
position: relative; |
||||
|
} |
||||
|
|
||||
|
.tagClass { |
||||
|
display: inline-block; |
||||
|
margin: 0 8px; |
||||
|
width: 200px; |
||||
|
position: relative; |
||||
|
} |
||||
|
</style> |
Loading…
Reference in new issue