diff --git a/ruoyi-ui/src/views/oa/project/report/index.vue b/ruoyi-ui/src/views/oa/project/report/index.vue index 0fcbaf2..38ef852 100644 --- a/ruoyi-ui/src/views/oa/project/report/index.vue +++ b/ruoyi-ui/src/views/oa/project/report/index.vue @@ -201,10 +201,37 @@ :closable="false" style="margin-bottom: 20px;"> + + + 如果浏览器无法获取定位,请按以下步骤操作: + + 在浏览器地址栏输入:edge://flags/#unsafely-treat-insecure-origin-as-secure(Edge) 或 chrome://flags/#unsafely-treat-insecure-origin-as-secure(Chrome) + 找到选项 "Insecure origins treated as secure" + 输入您的站点地址:http://49.232.154.205,然后设置为 Enabled + 重启浏览器,再尝试点击「重新获取定位」按钮 + + + - + + 重新获取定位 + + {{ workPlaceLocateError }} @@ -275,12 +302,19 @@ import { listDept } from "@/api/system/dept"; import { listUser } from "@/api/system/user"; import ProjectSelect from "@/components/fad-service/ProjectSelect"; import ProjectReportDetail from "@/views/oa/project/report/components/ProjectReportDetail.vue"; +import { + EMPTY_GEOCODE, + geolocationUserMessage, + resolveWorkPlaceFromBrowser +} from "@/utils/geolocationWorkPlace"; export default { name: "ProjectReport", components: {ProjectReportDetail, ProjectSelect}, data() { return { + workPlaceLoading: false, + workPlaceLocateError: "", // 按钮loading buttonLoading: false, detailVisible: false, @@ -356,6 +390,50 @@ export default { this.getUserList(); }, methods: { + /** + * @param {{ silent?: boolean, force?: boolean }} options + */ + async syncWorkPlaceFromGeolocation(options = {}) { + const silent = !!options.silent; + const force = !!options.force; + if (!force && this.form && this.form.reportId) { + return; + } + this.workPlaceLoading = true; + this.workPlaceLocateError = ""; + try { + const text = await resolveWorkPlaceFromBrowser(); + this.$set(this.form, "workPlace", text); + if (!silent) { + this.$modal.msgSuccess("已根据定位更新工作地点"); + } + } catch (e) { + console.error("[projectReport] 工作地点定位失败", e); + const msg = geolocationUserMessage(e); + this.workPlaceLocateError = msg; + this.$set(this.form, "workPlace", undefined); + const isBrowserGeoError = + e && + (e.code === 1 || + e.code === 2 || + e.code === 3 || + e.message === "BROWSER_UNSUPPORTED" || + e.message === EMPTY_GEOCODE); + if (isBrowserGeoError) { + this.$modal.msgWarning(msg); + } + } finally { + this.workPlaceLoading = false; + this.$nextTick(() => { + if (this.$refs.form) { + this.$refs.form.validateField("workPlace"); + } + }); + } + }, + refreshWorkPlace() { + this.syncWorkPlaceFromGeolocation({ silent: false, force: true }); + }, /** 查询详情 */ openDetail(row) { getProjectReport(row.reportId).then(response => { @@ -369,11 +447,14 @@ export default { this.reset(); this.open = true; this.title = "补录项目报工"; + this.$nextTick(() => { + this.syncWorkPlaceFromGeolocation({ silent: true, force: false }); + }); }, /** 检查今日报工 */ checkTodayReport() { - getTodayProjectReport().then(response => { + return getTodayProjectReport().then(response => { if (response.data && response.data.reportId) { this.hasTodayReport = true; this.todayReportId = response.data.reportId; @@ -426,6 +507,8 @@ export default { }, // 表单重置 reset() { + this.workPlaceLoading = false; + this.workPlaceLocateError = ""; this.form = { reportId: undefined, handler: undefined, @@ -472,9 +555,15 @@ export default { handleAdd() { this.reset(); this.suppVisible = false; - this.checkTodayReport(); - this.open = true; this.title = "添加项目报工"; + this.checkTodayReport().finally(() => { + this.open = true; + this.$nextTick(() => { + if (!this.form.reportId) { + this.syncWorkPlaceFromGeolocation({ silent: true, force: false }); + } + }); + }); }, /** 修改按钮操作 */ handleUpdate(row) { @@ -560,3 +649,12 @@ export default { } }; + + diff --git a/ruoyi-ui/src/views/oa/project/report/my.vue b/ruoyi-ui/src/views/oa/project/report/my.vue index 3de0f3d..4242ed9 100644 --- a/ruoyi-ui/src/views/oa/project/report/my.vue +++ b/ruoyi-ui/src/views/oa/project/report/my.vue @@ -107,8 +107,7 @@
如果浏览器无法获取定位,请按以下步骤操作:
edge://flags/#unsafely-treat-insecure-origin-as-secure
chrome://flags/#unsafely-treat-insecure-origin-as-secure
http://49.232.154.205