forked from jinyaoMa/my-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
467 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package service | ||
|
||
var ( | ||
instance *service | ||
) | ||
|
||
type service struct { | ||
Settings *settings | ||
} | ||
|
||
func init() { | ||
instance = &service{ | ||
Settings: &settings{}, | ||
} | ||
} | ||
|
||
func Settings() *settings { | ||
return instance.Settings | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package service | ||
|
||
import ( | ||
"my-app/backend/app" | ||
"my-app/backend/model" | ||
) | ||
|
||
type settings struct{} | ||
|
||
func (s *settings) SaveOption(name string, value string) error { | ||
option := model.MyOption{ | ||
Name: name, | ||
} | ||
result := option.Update(value) | ||
if result.Error == nil { | ||
switch name { | ||
case app.CfgDisplayLanguage: | ||
app.App().Config().DisplayLanguage = value | ||
case app.CfgColorTheme: | ||
app.App().Config().ColorTheme = value | ||
case app.CfgLogPath: | ||
app.App().Config().LogPath = value | ||
case app.CfgWebPortHttp: | ||
app.App().Config().Web.PortHttp = value | ||
case app.CfgWebPortHttps: | ||
app.App().Config().Web.PortHttps = value | ||
case app.CfgWebDirCerts: | ||
app.App().Config().Web.DirCerts = value | ||
} | ||
} | ||
return result.Error | ||
} | ||
|
||
func (s *settings) GetOption(name string) string { | ||
switch name { | ||
case app.CfgDisplayLanguage: | ||
return app.App().Config().DisplayLanguage | ||
case app.CfgColorTheme: | ||
return app.App().Config().ColorTheme | ||
case app.CfgLogPath: | ||
return app.App().Config().LogPath | ||
case app.CfgWebPortHttp: | ||
return app.App().Config().Web.PortHttp | ||
case app.CfgWebPortHttps: | ||
return app.App().Config().Web.PortHttps | ||
case app.CfgWebDirCerts: | ||
return app.App().Config().Web.DirCerts | ||
} | ||
return "" | ||
} | ||
|
||
func (s *settings) GetOptions() *app.Config { | ||
return app.App().Config() | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { App } from "vue"; | ||
import Form from "./src/form.vue"; | ||
import FormItem from "./src/form-item.vue"; | ||
import FormGroup from "./src/form-group.vue"; | ||
|
||
Form.install = (app: App) => { | ||
app.component(Form.name, Form); | ||
app.component(FormItem.name, FormItem); | ||
app.component(FormGroup.name, FormGroup); | ||
}; | ||
|
||
export default Form; | ||
export const MyForm = Form; | ||
export const MyFormItem = FormItem; | ||
export const MyFormGroup = FormGroup; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<template> | ||
<fieldset class="my-form-group" :style="style"> | ||
<legend class="my-form-group__legend">{{ props.legend }}</legend> | ||
<slot></slot> | ||
</fieldset> | ||
</template> | ||
|
||
<script setup lang="ts" name="MyFormGroup"> | ||
import { computed, inject, StyleValue, withDefaults } from "vue"; | ||
import { Size, SizeRef } from "../../types"; | ||
const props = withDefaults( | ||
defineProps<{ | ||
legend?: string; | ||
size?: Size; | ||
labelWidth?: string; | ||
}>(), | ||
{} | ||
); | ||
const formSize = inject<SizeRef>("my-form-size"); | ||
const style = computed<StyleValue>(() => { | ||
const size = props.size || formSize?.value; | ||
let width = "--my-border-width"; | ||
let radius = "--my-border-radius"; | ||
let space = "--my-space"; | ||
switch (size) { | ||
case "large": | ||
width += "-lg"; | ||
radius += "-lg"; | ||
space += "-lg"; | ||
break; | ||
case "small": | ||
width += "-sm"; | ||
radius += "-sm"; | ||
space += "-sm"; | ||
} | ||
return { | ||
borderWidth: `var(${width})`, | ||
borderRadius: `var(${radius})`, | ||
padding: `var(${space}) calc(0.4em + var(${space})) calc(0.275em + var(${space}))`, | ||
margin: `0 var(${width}) var(${space})`, | ||
}; | ||
}); | ||
</script> | ||
|
||
<style lang="scss"> | ||
.my-form-group { | ||
border-style: solid; | ||
border-color: var(--my-color-border-lighter); | ||
&__legend { | ||
font-size: var(--my-font-size-xs); | ||
color: var(--my-color-text-secondary); | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<template> | ||
<div class="my-form-item"> | ||
<label | ||
class="my-form-item__label" | ||
v-if="props.label" | ||
:for="props.for" | ||
:style="labelStyle" | ||
>{{ props.label }}</label | ||
> | ||
<slot></slot> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts" name="MyFormItem"> | ||
import { computed, StyleValue, withDefaults } from "vue"; | ||
import { LabelPosition } from "../../types"; | ||
const props = withDefaults( | ||
defineProps<{ | ||
label?: string; | ||
for?: string; | ||
labelPosition?: LabelPosition; | ||
labelWidth?: string; | ||
}>(), | ||
{} | ||
); | ||
const labelStyle = computed<StyleValue>(() => { | ||
const width = props.labelWidth; | ||
return { | ||
width, | ||
}; | ||
}); | ||
</script> | ||
|
||
<style lang="scss"> | ||
.my-form-item { | ||
&:not(:last-child) { | ||
margin-bottom: 0.5em; | ||
} | ||
&__label { | ||
display: inline-block; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<template> | ||
<form class="my-form"> | ||
<slot></slot> | ||
</form> | ||
</template> | ||
|
||
<script setup lang="ts" name="MyForm"> | ||
import { onUpdated, provide, ref, withDefaults } from "vue"; | ||
import { LabelPosition, LabelPositionRef, Size, SizeRef } from "../../types"; | ||
const props = withDefaults( | ||
defineProps<{ | ||
size?: Size; | ||
labelPosition?: LabelPosition; | ||
labelWidth?: string; | ||
}>(), | ||
{ | ||
size: "default", | ||
labelPosition: "left", | ||
labelWidth: "auto", | ||
} | ||
); | ||
const formSize = ref<Size>(props.size); | ||
const formLabelPosition = ref<LabelPosition>(props.labelPosition); | ||
provide<SizeRef>("my-form-size", formSize); | ||
provide<LabelPositionRef>("my-form-label-position", formLabelPosition); | ||
onUpdated(() => { | ||
formSize.value = props.size; | ||
formLabelPosition.value = props.labelPosition; | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.