SourceDetail.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <!--
  2. * @Author: sujunling
  3. * @Date: 2023-08-15 22:08:21
  4. * @LastEditors: sujunling
  5. * @LastEditTime: 2023-08-17 15:59:13
  6. * @FilePath: \xld-gis-admin\src\views\resource\map\SourceDetail.vue
  7. * @Description: 地图资源明细界面
  8. -->
  9. <template>
  10. <div class="source-detail">
  11. <a-form ref="formRef" :model="formState" :rules="rules" style="width: 100%">
  12. <div class="compontents">
  13. <div class="title">基本信息</div>
  14. <a-row class="form-container">
  15. <a-col :span="12" class="form-col">
  16. <a-form-item ref="servicename" label="组件名称" name="servicename" class="label-form-item">
  17. <a-input v-model:value="formState.servicename" placeholder="请输入组件名称" :disabled="isView" />
  18. </a-form-item>
  19. </a-col>
  20. <a-col :span="12" class="form-col">
  21. <a-form-item ref="servicealiasname" label="组件别名" name="servicealiasname" class="label-form-item">
  22. <a-input v-model:value="formState.servicealiasname" placeholder="请输入组件别名" :disabled="isView" />
  23. </a-form-item>
  24. </a-col>
  25. <a-col :span="24" class="form-col">
  26. <a-form-item ref="description" label="组件描述" name="description" class="label-form-item">
  27. <a-textarea placeholder="请输入组件描述" v-model:value="formState.description" :rows="2" :disabled="isView" />
  28. </a-form-item>
  29. </a-col>
  30. <a-col :span="24" class="form-col">
  31. <a-form-item ref="bz" label="授权文件" name="bz" class="label-form-item">
  32. <a-input v-model:value="formState.bz" placeholder="请输入授权文件地址" :disabled="isView" />
  33. </a-form-item>
  34. </a-col>
  35. <!-- <a-col :span="9" class="form-col">
  36. <a-form-item ref="servicetype" label="适合申请流程" name="servicetype" class="label-form-item">
  37. <a-select v-model:value="formState.servicetype">
  38. <template v-for="(tag, index) in assemblyType" :key="index">
  39. <a-select-option :value="tag.value">{{ tag.value }}</a-select-option>
  40. </template>
  41. </a-select>
  42. </a-form-item>
  43. </a-col> -->
  44. <a-col :span="12" class="form-col">
  45. <!-- <a-form-item ref="servicetype" label="资源类型" name="servicetype" class="label-form-item">
  46. <a-select v-model:value="formState.servicetype">
  47. <template v-for="(tag, index) in assemblyType" :key="index">
  48. <a-select-option :value="tag.value">{{ tag.value }}</a-select-option>
  49. </template>
  50. </a-select>
  51. </a-form-item> -->
  52. <a-form-item ref="servicetype" label="组件类型" name="servicetype" class="label-form-item">
  53. <a-select v-model:value="formState.servicetype" :disabled="isView" placeholder="请输入组件类型">
  54. <template v-for="tag in assemblyType" :key="tag.value">
  55. <a-select-option :value="tag.value" :disabled="isView">{{ tag.label }}</a-select-option>
  56. </template>
  57. </a-select>
  58. </a-form-item>
  59. </a-col>
  60. <a-col :span="12" class="form-col">
  61. <a-form-item ref="crs" label="组内顺序" name="crs" class="label-form-item">
  62. <a-input v-model:value="formState.crs" :rows="2" :disabled="isView" />
  63. </a-form-item>
  64. </a-col>
  65. <a-col :span="8" class="form-col">
  66. <a-form-item ref="thumbnail" label="缩略图" name="thumbnail" class="label-form-item">
  67. <a-upload :beforeUpload="beforeUploadImg" :remove="removeImg" :custom-request="customUpload"
  68. v-model:file-list="fileList" :disabled="isViewImg">
  69. <a-button style="background-color: #0671dd; color: #fff; border-radius: 4px" :disabled="isView">
  70. <upload-outlined></upload-outlined>
  71. 文件上传
  72. </a-button>
  73. </a-upload>
  74. <span class="updateImg" @click="imgBut" v-if="!isView"></span>
  75. </a-form-item>
  76. </a-col>
  77. <a-col :span="16" class="form-col">
  78. <div class="wrapperImg" v-if="formState.mapingurl">
  79. <img v-if="formState.mapingurl" :id="formState.mapingurl" :src="getImg(formState.mapingurl)" alt="图片">
  80. <!-- <p v-else>无预览图</p> -->
  81. </div>
  82. </a-col>
  83. </a-row>
  84. </div>
  85. </a-form>
  86. </div>
  87. </template>
  88. <script lang="ts">
  89. import {
  90. defineComponent,
  91. ref,
  92. toRefs,
  93. reactive,
  94. UnwrapRef,
  95. onMounted,
  96. watch,
  97. } from 'vue';
  98. import { BasicForm } from '/@/components/Form/index';
  99. import { UploadOutlined } from '@ant-design/icons-vue';
  100. import { ValidateErrorEntity } from 'ant-design-vue/es/form/interface';
  101. import { useMessage } from '/@/hooks/web/useMessage';
  102. // 加载菜单数据
  103. import Moment from 'moment';
  104. import { insertService, updateService, update, getImgUrl } from '/@/api/dataAdmin/assembly';
  105. import { session } from '/@/utils/Memory.js';
  106. import { message } from 'ant-design-vue';
  107. const props = {
  108. formData: { type: Object, default: ref(null) },
  109. isView: { type: Boolean, default: ref(false) },
  110. isUpdate: { type: Boolean, default: ref(false) },
  111. };
  112. interface FormState {
  113. source: '',
  114. servicetype: string,
  115. publiccurl: string;
  116. servicename: string;
  117. mapingurl: string,
  118. servicealiasname: string;
  119. description: string;
  120. publishtime: string;
  121. publisher: string;
  122. updateType: string;
  123. updatetime: string;
  124. public: boolean;
  125. share: boolean;
  126. searched: boolean;
  127. externalApply: boolean;
  128. date1: undefined;
  129. bz: string,
  130. crs: 0
  131. }
  132. export default defineComponent({
  133. name: 'SourceDetail',
  134. components: { BasicForm, UploadOutlined },
  135. props,
  136. setup(props, { emit }) {
  137. const data = reactive({
  138. detail: props.formData,
  139. isUpdate: props.isUpdate,
  140. isView: props.isView,
  141. });
  142. var fileList = ref([]);
  143. var isViewImg = ref(false);
  144. var assemblyType = ref([
  145. { value: '地图浏览工具', label: '地图浏览工具', },
  146. { value: '服务加载工具', label: '服务加载工具', },
  147. { value: 'GIS功能工具', label: 'GIS功能工具', },
  148. { value: '空间分析工具', label: '空间分析工具', },
  149. { value: '三维可视化效果工具', label: '三维可视化效果工具', },
  150. ])
  151. const formRef = ref();
  152. const formState: UnwrapRef<FormState> = reactive({
  153. mapingurl: '',
  154. servicename: '',
  155. publiccurl: '',
  156. servicealiasname: '',
  157. servicetype: undefined,
  158. description: '',
  159. publishtime: '',
  160. publisher: '',
  161. updateType: '',
  162. updatetime: '',
  163. coordinate: '',
  164. public: true,
  165. share: true,
  166. searched: true,
  167. externalApply: true,
  168. date1: undefined,
  169. crs: 0
  170. });
  171. const moment = Moment;
  172. const rules = {
  173. // mapingurl: [{ required: true, message: '请输入服务地址', trigger: 'blur' }],
  174. bz: [{ required: true, message: '请输入授权文件地址', trigger: 'blur' }],
  175. servicetype: [{ required: true, message: '请选择资源类型', trigger: 'change' }],
  176. servicename: [
  177. { required: true, message: '请填写组件名称', trigger: 'blur' },
  178. { min: 1, max: 20, message: '长度必须在3到20个字符', trigger: 'blur' },
  179. ],
  180. servicealiasname: [
  181. { required: true, message: '请输入组件别名', trigger: 'blur' },
  182. { min: 1, max: 20, message: '长度必须在3到20个字符', trigger: 'blur' },
  183. ],
  184. systag: [{ required: true, message: '请选择系统标签', trigger: 'change' }],
  185. date1: [{ required: true, message: 'Please pick a date', trigger: 'change', type: 'object' }],
  186. type: [
  187. {
  188. type: 'array',
  189. required: true,
  190. message: 'Please select at least one activity type',
  191. trigger: 'change',
  192. },
  193. ],
  194. resource: [{ required: true, message: 'Please select activity resource', trigger: 'change' }],
  195. desc: [{ required: true, message: 'Please input activity form', trigger: 'blur' }],
  196. };
  197. const { createMessage } = useMessage();
  198. watch(() => props.formData, (obj) => {
  199. data.detail = obj;
  200. if (data.isUpdate) setFormData()
  201. });
  202. watch(() => props.isUpdate, (obj) => {
  203. data.isUpdate = obj;
  204. if (!data.isUpdate && !props.isView) {
  205. resetForm()
  206. } else {
  207. setFormData()
  208. }
  209. });
  210. watch(
  211. () => props.isView,
  212. (obj) => {
  213. data.isView = obj;
  214. if (data.isView != undefined && data.isView != null) {
  215. setFormData()
  216. }
  217. }
  218. );
  219. const submitForm = () => {
  220. if (data.isView) {
  221. emit('closeModal');
  222. return
  223. }
  224. try {
  225. formRef.value
  226. .validate()
  227. .then(async () => {
  228. const params = setSubmitForm();
  229. if (params) {
  230. if (data.isUpdate) {
  231. params.servicebase.serviceid = data.detail.serviceid;
  232. params.servicebase.id = data.detail.id;
  233. if (!params.servicebase.mapingurl) params.servicebase.mapingurl = data.detail.mapingurl;
  234. params.metadata.serviceid = data.detail.serviceid;
  235. params.metadata.id = data.detail.id;
  236. if (!params.metadata.mapingurl) params.metadata.mapingurl = data.detail.mapingurl;
  237. const res = await updateService(params);
  238. if (res && res?.status !== '-1') {
  239. createMessage.success('修改组件资源成功!');
  240. fileList.value = [];
  241. resetForm();
  242. emit('RtnMain', true);
  243. } else createMessage.error('修改组件资源失败!,失败原因:' + res?.message, 1);
  244. } else {
  245. const res = await insertService(params);
  246. if (res && res?.status !== '-1') {
  247. createMessage.success('新增组件资源成功!');
  248. fileList.value = [];
  249. resetForm();
  250. emit('RtnMain', true);
  251. } else createMessage.error('新增组件资源失败!,失败原因:' + res?.message, 1);
  252. }
  253. }
  254. })
  255. .catch((error: ValidateErrorEntity<FormState>) => {
  256. createMessage.error('请完成必填信息!', 1);
  257. console.log('error', error);
  258. });
  259. } catch (ex) {
  260. console.log(ex);
  261. }
  262. };
  263. const resetForm = () => {
  264. formState.mapingurl = '';
  265. fileList.value = [];
  266. formRef.value.resetFields();
  267. };
  268. /**
  269. * 设置提交数据
  270. */
  271. const setSubmitForm = () => {
  272. const userinfo = session.getItem('userInfo');
  273. return {
  274. type: 'SR',
  275. servicebase: {
  276. publisher: userinfo?.EMPLOYEE?.NAME, //'系统管理员',
  277. username: userinfo?.EMPLOYEE?.NAME, //'系统管理员',
  278. userid: userinfo?.EMPLOYEE?.EMPLOYEE_ID, //'27AF004A-8BDN-885T-30FU-89DE3388762B',
  279. servicealiasname: formState.servicealiasname, //资源别名
  280. description: formState.description, //资源描述
  281. ispublic: formState.public ? '1' : '0', //是否公开
  282. searched: formState.searched ? '1' : '0', //是否展示
  283. externalApply: formState.externalApply ? '1' : '0', //外部申请
  284. servicename: formState.servicename, //资源名
  285. otherService: '',
  286. source: formState.servicetype, //资源类型
  287. mapingurl: formState.mapingurl, //服务地址
  288. publiccurl: formState.publiccurl, //数据表
  289. crs: formState.crs,//小组类顺序,
  290. bz: formState.bz,
  291. },
  292. metadata: {
  293. bz: formState.bz,
  294. crs: formState.crs,//小组类顺序
  295. publiccurl: formState.publiccurl, //数据表
  296. source: formState.servicetype, //资源类型
  297. mapingurl: formState.mapingurl, //服务地址
  298. name: formState.servicename, //资源名
  299. servicealiasname: formState.servicealiasname, //资源别名
  300. thumbnail: '',
  301. description: formState.description,
  302. updateType: formState.updateType, //更新方式
  303. workSpace: '',
  304. ishistory: '0',
  305. shsqlc: 'ggdata',
  306. urlInfo: '',
  307. otherService: '',
  308. ispublic: formState.public ? '1' : '0', //是否公开
  309. searched: formState.searched ? '1' : '0', //是否展示
  310. externalApply: formState.externalApply ? '1' : '0', //外部申请
  311. isShow: formState.share ? '1' : '0',
  312. publisher: userinfo?.EMPLOYEE?.NAME, //'系统管理员',
  313. username: userinfo?.EMPLOYEE?.NAME, //'系统管理员',
  314. userid: userinfo?.EMPLOYEE?.EMPLOYEE_ID, //'27AF004A-8BDN-885T-30FU-89DE3388762B',
  315. }
  316. };
  317. };
  318. /**
  319. * 设置表单数据
  320. */
  321. const setFormData = () => {
  322. formState.public = data.detail?.ispublic === '1' ? true : false;
  323. formState.servicename = data.detail?.servicename;
  324. formState.publiccurl = data.detail?.publiccurl;
  325. formState.servicetype = data.detail?.source;
  326. formState.crs = data.detail?.crs;
  327. formState.description = data.detail?.description;
  328. formState.mapingurl = data.detail?.mapingurl;
  329. formState.publishtime = data.detail?.publishdate;
  330. formState.publishtime = data.detail?.publishdate ? moment(data.detail?.publishdate).format('YYYY-MM-DD HH:mm:ss') : '';
  331. formState.publisher = data.detail?.publisher;
  332. formState.bz = data.detail?.bz;
  333. formState.servicealiasname = data.detail?.servicealiasname;
  334. formState.updatetime = data.detail?.updatedate ? moment(data.detail?.updatedate).format('YYYY-MM-DD HH:mm:ss') : '';
  335. formState.searched = data.detail?.searched === 0 ? false : true;
  336. };
  337. onMounted(() => {
  338. resetForm();
  339. });
  340. function beforeUploadImg() {
  341. }
  342. function removeImg() {
  343. formState.mapingurl = '';
  344. }
  345. function imgBut() {
  346. if (fileList.value.length) {
  347. return message.error('只能上传一个文件,请先删除之前的文件!')
  348. } else if (fileList.value.length == 0) {
  349. document.getElementById("thumbnail").click()
  350. }
  351. }
  352. function customUpload({ file, onSuccess, onError }) {
  353. const formData = new FormData();
  354. formData.append('file', file);
  355. update(formData, session.getItem('sysFild').dirId).then(r => {
  356. if (r && r.resp_code == 0 && r.resp_msg == "OK") {
  357. formState.mapingurl = `${r.datas.id},${r.datas.dirId}`;
  358. // isViewImg.value = true;
  359. onSuccess()
  360. } else {
  361. onError()
  362. }
  363. })
  364. }
  365. //获取图片
  366. function getImg(i) {
  367. if (i) {
  368. var arr = i.split(',')
  369. arr.length > 1 && getImgUrl(arr[0], arr[1]).then(r => {
  370. var d = document.getElementById(i);
  371. if (d) d.src = r;
  372. })
  373. }
  374. }
  375. return {
  376. imgBut,
  377. removeImg,
  378. beforeUploadImg,
  379. getImg,
  380. fileList,
  381. isViewImg,
  382. assemblyType,
  383. customUpload,
  384. ...toRefs(data),
  385. formRef,
  386. moment,
  387. rules,
  388. formState,
  389. submitForm,
  390. resetForm,
  391. createMessage,
  392. setSubmitForm,
  393. setFormData,
  394. };
  395. },
  396. });
  397. </script>
  398. <style scoped lang="less">
  399. .updateImg {
  400. top: 0px;
  401. display: inline-block;
  402. background-color: rgb(6, 113, 221);
  403. color: rgb(255, 255, 255);
  404. border-radius: 4px;
  405. width: 110px;
  406. height: 32px;
  407. position: absolute;
  408. opacity: 0;
  409. cursor: pointer;
  410. z-index: 2;
  411. }
  412. .wrapperImg {
  413. width: 200px;
  414. height: 200px;
  415. overflow: hidden;
  416. border: solid 1px #eee;
  417. }
  418. .wrapperImg img {
  419. width: 200px;
  420. height: 200px;
  421. }
  422. .source-detail {
  423. height: 100%;
  424. width: 100%;
  425. padding: 0 20px;
  426. .compontents {
  427. width: 100%;
  428. height: auto;
  429. .title {
  430. height: 19px;
  431. line-height: 18px;
  432. padding-left: 6px;
  433. margin-bottom: 20px;
  434. border-left: 3px solid #0671dd;
  435. font-family: Source Han Sans CN;
  436. font-size: 16px;
  437. font-weight: 350;
  438. letter-spacing: 0px;
  439. }
  440. .form-container {
  441. width: 100%;
  442. height: auto;
  443. .form-col {
  444. height: 100%;
  445. }
  446. .form-col-left {
  447. padding-right: 20px;
  448. }
  449. }
  450. }
  451. }
  452. .label-form-item {
  453. :deep(.ant-form-item-label) {
  454. width: 90px;
  455. }
  456. :deep(.ant-form-item-control) {
  457. width: calc(100% - 90px);
  458. }
  459. }
  460. </style>