Skip to content

Commit

Permalink
chore: 更新实现
Browse files Browse the repository at this point in the history
  • Loading branch information
GongCx-Github committed Jul 5, 2023
1 parent fc529d2 commit d3b7dcb
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 79 deletions.
38 changes: 20 additions & 18 deletions js/src/admin/components/ExtensionSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,13 @@ import ExtensionPage from 'flarum/admin/components/ExtensionPage'
import extractText from 'flarum/common/utils/extractText'
import linkify from '../../utils/linkify'
import type Mithril from 'mithril'
import IPInfo from "../../forum/Model/IPInfo"
import IPInfo from '../../forum/Model/IPInfo'

interface ServiceData {
name: string
}
interface ReducerInitialValue {
[name: string]: NestedStringArray
}

export default class GeoipSettingsPage extends ExtensionPage {
export default class GeoIPSettingsPage extends ExtensionPage {
oninit(vnode: Mithril.Vnode<object, this>) {
super.oninit(vnode)
}
Expand All @@ -41,7 +38,7 @@ export default class GeoipSettingsPage extends ExtensionPage {
),
},
}),
{} as ReducerInitialValue
{} as Record<string, NestedStringArray>
)
return (
<div className='container'>
Expand All @@ -67,18 +64,23 @@ export default class GeoipSettingsPage extends ExtensionPage {
})}
</div>
<div className='Form-group'>
{this.buildSettingComponent({
type: "text",
setting: `gbcl-userip.service.badgeOptions`,
label: app.translator.trans('gbcl-userip.admin.service.badgeOptionsLabel'),
help: `Use '|' to split.Available Options: ${serviceAllAttrs.toString()}`
})}
{this.buildSettingComponent({
type: "text",
setting: `gbcl-userip.service.hoverOptions`,
label: app.translator.trans('gbcl-userip.admin.service.hoverOptionsLabel'),
help: `Use '|' to split.Available Options: ${serviceAllAttrs.toString()}`
})}
{this.buildSettingComponent({
type: 'text',
setting: `gbcl-userip.service.badgeOptions`,
label: app.translator.trans(
'gbcl-userip.admin.service.badgeOptionsLabel'
),
help: `Use '|' to split. Available Options: ${serviceAllAttrs.toString()}`,
})}

{this.buildSettingComponent({
type: 'text',
setting: `gbcl-userip.service.hoverOptions`,
label: app.translator.trans(
'gbcl-userip.admin.service.hoverOptionsLabel'
),
help: `Use '|' to split. Available Options: ${serviceAllAttrs.toString()}`,
})}
</div>
{this.submitButton()}
</div>
Expand Down
4 changes: 0 additions & 4 deletions js/src/forum/ProcessData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,4 @@ export default class ProcessData {

return elements
}

getAllElements() {
return Object.keys(this)
}
}
50 changes: 29 additions & 21 deletions js/src/forum/components/GeoIpToolBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,51 @@
import Component, { ComponentAttrs } from 'flarum/common/Component'
import { Data } from '../ProcessData'
import app from 'flarum/forum/app'
import Tooltip from "flarum/common/components/Tooltip";
import Tooltip from 'flarum/common/components/Tooltip'

const BADGE_OPTIONS_KEY = 'badgeOptions'
const HOVER_OPTIONS_KEY = 'hoverOptions'

export interface GeoIpBarAttrs extends ComponentAttrs {
elements: Data
}

interface Settings {
service: {
[BADGE_OPTIONS_KEY]: string
[HOVER_OPTIONS_KEY]: string
}
}

enum Service {
Badge,
Hover,
}

export default class GeoIpToolBar<
CustomAttrs extends GeoIpBarAttrs = GeoIpBarAttrs
> extends Component<CustomAttrs> {
view() {
const settings = JSON.parse(app.forum.attribute('GbclUserIp'));
const settings = JSON.parse(app.forum.attribute('GbclUserIp')) as Settings

return (
<Tooltip text={this.getTooltipOptions(settings)}>
<Tooltip text={this.getOptions(Service.Hover, settings)}>
<div className='userIp-container'>
<div className='ip-locate' id='info-country'>
{`${this.getBadgeOptions(settings)}`}
{`${this.getOptions(Service.Badge, settings)}`}
</div>
</div>
</Tooltip>
)
}

getBadgeOptions(settings: any): string {
const { elements } = this.attrs
const settingAttrs = settings.service.badgeOptions

return settingAttrs.split('|').map((value: string) => {
return `${elements[value]} | `
})
}

getTooltipOptions(settings: any): string {
const { elements } = this.attrs
const settingAttrs = settings.service.hoverOptions

return settingAttrs.split('|').map((value: string) => {
return `${elements[value]} | `
})

getOptions(service: Service, settings: Settings) {
const { elements } = this.attrs

return settings.service[
service === Service.Badge ? BADGE_OPTIONS_KEY : HOVER_OPTIONS_KEY
]
.split('|')
.map(value => `${elements[value]} |`)
}
}
17 changes: 8 additions & 9 deletions js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"extends": "flarum-tsconfig",
"include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*"],
"compilerOptions": {
"declarationDir": "./dist-typings",
"baseUrl": ".",
"paths": {
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
}
"extends": "flarum-tsconfig",
"include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*"],
"compilerOptions": {
"declarationDir": "./dist-typings",
"baseUrl": ".",
"paths": {
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
}
}
}
6 changes: 4 additions & 2 deletions resources/less/forum.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,27 @@
* file that was distributed with this source code.
*/


button.Button.Button--primary.ip-locate {
margin-top: 8px;
padding: 7px;
margin-left: 0;
}

.userIp-container {
flex-wrap: wrap;
display: flex;
}

.ip-locate {
margin-left: 10px;
margin-bottom: 6px;
padding: 2px 5px 2px 5px;
border: 1px solid #cad0db;
border-radius: 6px;
}

body when (@config-dark-mode = true) {
.ip-locate {
border: 1px solid #1b2028;
}
}
}
50 changes: 25 additions & 25 deletions resources/locale/en.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
gbcl-userip:
forum:
unknownNotice: Unknown
forum:
unknownNotice: Unknown

admin:
permissions:
view_ip_info_label: Display IP Info
admin:
permissions:
view_ip_info_label: Display IP Info

service:
label: Service
badgeOptionsLabel: Badge Options
hoverOptionsLabel: Hover Options
service:
label: Service
badgeOptionsLabel: Badge Options
hoverOptionsLabel: Hover Options

ipsb:
label: IP.SB
description: Use <b>https://ip.sb</b> to get free IP location information (please note the rate limit)
ovincApi:
label: Ovinc Inner Api
description: Inner Api for Customer
areaCode: Area Code
backboneIsp: Backbone ISP
district: District
province: Province
isp: ISP
countryCode: Country Code
region: Region
city: City
ipsb:
label: IP.SB
description: Use <b>https://ip.sb</b> to get free IP location information (please note the rate limit)

ovincApi:
label: Ovinc Inner Api
description: Inner Api for Customer

areaCode: Area Code
backboneIsp: Backbone ISP
district: District
province: Province
isp: ISP
countryCode: Country Code
region: Region
city: City

0 comments on commit d3b7dcb

Please sign in to comment.