uploadsketch.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482
  1. <template>
  2. <view style="position: relative;">
  3. <!-- 胶囊 -->
  4. <mvBar :mysNavConfig="mysNavConfig"></mvBar>
  5. <view :style="{marginTop:navH}"></view>
  6. <view @click="toRecord()" style="margin-bottom:20rpx">
  7. <view style="display: flex;justify-content: center;">
  8. <image style="height: 60rpx;width: 60rpx;" src="../../static/img/icon-clock.png"></image>
  9. </view>
  10. <view style="display: flex;justify-content: center;">
  11. <p style="font-size: 30rpx;">查看修改/反馈记录</p>
  12. </view>
  13. </view>
  14. <view v-if="!loading && !onlyShow">
  15. <view style="display: flex;justify-content: center;">
  16. <radio-group @change="chan">
  17. <label v-for="item in radioGroup" :key="item">
  18. <view style="display: inline;margin: 0 20rpx">
  19. <radio :value="item" :checked="item==activeRadio" color="#fdd544" />{{item}}
  20. </view>
  21. </label>
  22. </radio-group>
  23. </view>
  24. <view style="margin: 30rpx;display: flex;justify-content: center;" v-if="activeRadio == '图文'">
  25. <htz-image-upload :max="18" mediaType="image" name="file" :chooseNum="9" v-model="imageData"
  26. @chooseSuccess="ceshiChooseSuccess1">
  27. </htz-image-upload>
  28. </view>
  29. <view style="margin: 30rpx;display: flex;justify-content: center;" v-if="activeRadio == '视频'">
  30. <htz-image-upload :max="1" mediaType="video" name="file" :chooseNum="1" v-model="videoData"
  31. @chooseSuccess="ceshiChooseSuccess2">
  32. </htz-image-upload>
  33. </view>
  34. <view style="padding: 20rpx 30rpx 0;">
  35. <uni-easyinput type="text" :inputBorder="false" v-model="title" placeholder="在此填写让人眼前一亮的标题吧"
  36. :placeholderStyle="placeholderStyle">
  37. </uni-easyinput>
  38. </view>
  39. <!-- 多行输入框 -->
  40. <view style="padding: 40rpx 30rpx 150rpx;font-size: 30rpx;">
  41. <textarea v-model="text" maxlength="2000" auto-height="true" placeholder="添加正文" />
  42. </view>
  43. <view class="signup">
  44. <button type="default" class="but1" :loading="loading" :class="{'on':item.title == '1',}"
  45. @click="submit()">
  46. 提交初稿</button>
  47. </view>
  48. </view>
  49. <view v-if="!loading && onlyShow">
  50. <view v-if="activeRadio == '图文'">
  51. <view class="image-list">
  52. <!-- 图文 -->
  53. <view class="image-item" v-for="photo in imageData">
  54. <image :src="photo" mode="aspectFill" style="width: 100%;height: 100%;"
  55. @click="handlePreviewImage1(photo)"></image>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 视频 -->
  60. <view style="display: flex;align-items: center;justify-content: center;" v-if="activeRadio == '视频'">
  61. <video :src="videoData[0]"></video>
  62. </view>
  63. <view>
  64. <p style="font-size: 30rpx;padding: 20rpx 30rpx 0 ;">{{title}}</p>
  65. <view style="padding: 40rpx 30rpx 150rpx;font-size: 30rpx;">
  66. <text style="font-size: 30rpx;"> {{text}}</text>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. import mvBar from "@/components/mys_navBar/mysNavBar";
  74. import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue';
  75. import getPolicyEncode from '@/components/obs/getPolicy.js';
  76. import getSignature from '@/components/obs/GetSignature.js';
  77. export default {
  78. components: {
  79. mvBar,
  80. htzImageUpload,
  81. },
  82. data() {
  83. return {
  84. onlyShow: false,
  85. loading: true,
  86. placeholderStyle: "font-size: 30rpx;",
  87. navH: getApp().globalData.navHeight,
  88. taskId: "",
  89. title: "",
  90. text: "",
  91. sketchStatus: "",
  92. activeRadio: '图文', //存的是选中的value值
  93. radioGroup: ['图文', '视频'],
  94. videoData: [],
  95. imageData: [],
  96. mysNavConfig: {
  97. /* 开启单页显示首页图标 */
  98. isHome: true,
  99. /* 固定导航 */
  100. navFixed: true,
  101. /* 标题 (屏幕中心居中 两边图标中心居中使用slot center1) */
  102. navTitle: {
  103. text: "上传初稿",
  104. color: "",
  105. fontSize: "32rpx", // px upx rpx
  106. fontWeight: "normal", // 100 - 700
  107. },
  108. btnType: "type2",
  109. onLeftClick: '',
  110. /* type2 按钮 */
  111. type2Config: {
  112. // 左图标
  113. leftPath: "/static/img/png2.png",
  114. // 右图标
  115. rightPath: "/static/img/png4.png",
  116. // 圆角
  117. radius: "40rpx",
  118. },
  119. },
  120. }
  121. },
  122. onLoad(options) {
  123. let data = options.textObj.replace(/""/g, "");
  124. data = JSON.parse(decodeURIComponent(data))
  125. this.taskId = data.taskId
  126. this.sketchStatus = data.sketchStatus
  127. this.getSketch()
  128. },
  129. methods: {
  130. chan(e) {
  131. this.activeRadio = e.detail.value;
  132. console.log(this.activeRadio);
  133. },
  134. handlePreviewImage1(item) {
  135. console.log("image src: ", item)
  136. let that = this
  137. wx.previewImage({
  138. current: item, // 当前显示图片的http链接
  139. urls: that.imageData // 需要预览的图片http链接列表
  140. })
  141. },
  142. async getSketch() {
  143. this.loading = true
  144. uni.showLoading({
  145. title: '加载中'
  146. });
  147. await this.$https.get('/youngee/c/t/g/get-unsubmit-task-sketch' +
  148. "?" +
  149. "task_id" +
  150. "=" +
  151. this.taskId)
  152. .then(res => {
  153. console.log(res)
  154. if (res.data.data != null) {
  155. this.onlyShow = true
  156. this.title = res.data.data.title
  157. this.text = res.data.data.content
  158. if (res.data.data.type == 1) { // 图文
  159. this.activeRadio = '图文'
  160. for (var j = 0; j < res.data.data.Photo.length; j++) {
  161. this.imageData.push(res.data.data.Photo[j].photo_url)
  162. }
  163. } else if (res.data.data.type == 2) { //视频
  164. this.activeRadio = '视频'
  165. for (var j = 0; j < res.data.data.Photo.length; j++) {
  166. this.videoData.push(res.data.data.Photo[j].photo_url)
  167. }
  168. }
  169. }
  170. })
  171. uni.hideLoading();
  172. this.loading = false
  173. },
  174. toRecord() {
  175. var data = {
  176. taskId: this.taskId,
  177. };
  178. data = JSON.stringify(data)
  179. uni.navigateTo({
  180. url: '/pages/workspace/sketchrecord?textObj=' + encodeURIComponent(data)
  181. });
  182. },
  183. submit() {
  184. // 检验标题和内容是否为空
  185. let type = 0
  186. let photourl = []
  187. if (this.activeRadio == '图文') { // 图文
  188. type = 1
  189. photourl = this.imageData
  190. } else {
  191. type = 2
  192. photourl = this.videoData
  193. }
  194. if (photourl.length == 0) {
  195. uni.showToast({
  196. title: "请上传初稿图片或视频",
  197. icon: 'none'
  198. })
  199. return
  200. }
  201. if (type === 1) {
  202. if (this.title == '') {
  203. uni.showToast({
  204. title: "请填写初稿标题",
  205. icon: 'none'
  206. })
  207. return
  208. }
  209. if (this.text == '') {
  210. uni.showToast({
  211. title: "请填写初稿内容",
  212. icon: 'none'
  213. })
  214. return
  215. }
  216. }
  217. console.log("photourl:", photourl)
  218. let that = this
  219. uni.showModal({
  220. title: '提示',
  221. content: '提交后无法修改并进行审核,确认提交?',
  222. success: async function(res) {
  223. if (res.confirm) {
  224. await that.$https.post('/youngee/c/t/p/add-task-sketch', {
  225. task_id: that.taskId,
  226. title: that.title,
  227. content: that.text,
  228. type: type,
  229. photo_url: photourl.toString()
  230. })
  231. .then(res => {
  232. console.log(res)
  233. })
  234. await that.$https.get('/youngee/c/t/g/submit-task-sketch' +
  235. "?" +
  236. "task_id" +
  237. "=" +
  238. that.taskId)
  239. .then(res => {
  240. console.log(res)
  241. })
  242. uni.navigateBack()
  243. } else if (res.cancel) {
  244. console.log('用户点击取消');
  245. }
  246. }
  247. });
  248. },
  249. ceshiChooseSuccess1(tempFilePaths, e) { //选择图文返回
  250. console.log('ceshiChooseSuccess', tempFilePaths, e);
  251. /****************
  252. 以下代码是自定义上传逻辑,仅供参考
  253. ***************/
  254. this.imgUpload1(tempFilePaths, e);
  255. /*******************************/
  256. console.log("imgdata" + this.imageData)
  257. },
  258. imgUpload1(tempFilePaths, e) {
  259. let that = this
  260. console.log('imgUpload', tempFilePaths)
  261. let config = {
  262. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  263. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  264. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  265. };
  266. for (let i = 0; i < tempFilePaths.length; ++i) {
  267. if (e == 0) {
  268. this.store = 'talent_upload/' + this.guid() + '.png'
  269. } else if (e == 1) {
  270. this.store = 'talent_upload/' + this.guid() + '.mp4'
  271. }
  272. let fileName = this.store; //指定上传到OBS桶中的对象名
  273. let OBSPolicy = { //设定policy内容
  274. "expiration": "2089-12-31T12:00:00.000Z",
  275. "conditions": [{
  276. "bucket": "horastar"
  277. }, //Bucket name
  278. // {"bucket": "goin"},
  279. {
  280. 'key': fileName
  281. }
  282. ]
  283. }
  284. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  285. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  286. uni.uploadFile({
  287. //url: config.EndPoint,
  288. url: config.EndPoint,
  289. filePath: tempFilePaths[i],
  290. name: 'file',
  291. formData: {
  292. 'AccessKeyID': config.AccessKeyId,
  293. 'policy': policyEncoded,
  294. 'signature': signature,
  295. 'key': fileName,
  296. },
  297. success: function(res) {
  298. console.log(res.statusCode); //打印响应状态码
  299. if (res.statusCode == '204') {
  300. that.imageData.push(config.EndPoint + '/' + fileName);
  301. console.log('上传图片成功', res)
  302. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  303. console.log(obs_url)
  304. // that.formData.home_img = obs_url
  305. uni.showToast({
  306. title: '上传成功',
  307. icon: '成功'
  308. });
  309. } else {
  310. console.log('上传图片失败', res)
  311. uni.showToast({
  312. title: '上传失败',
  313. icon: '失败'
  314. });
  315. }
  316. },
  317. fail: function(e) {
  318. console.log(e);
  319. uni.showToast({
  320. title: '上传失败22222',
  321. icon: '失败'
  322. });
  323. }
  324. })
  325. }
  326. },
  327. ceshiChooseSuccess2(tempFilePaths, e) { //选择视频返回
  328. console.log('ceshiChooseSuccess', tempFilePaths, e);
  329. if (e == 0) {
  330. this.store = 'talent_upload/' + this.guid() + '.png'
  331. } else if (e == 1) {
  332. this.store = 'talent_upload/' + this.guid() + '.mp4'
  333. }
  334. /****************
  335. 以下代码是自定义上传逻辑,仅供参考
  336. ***************/
  337. this.imgUpload2(tempFilePaths);
  338. /*******************************/
  339. console.log("videoData" + this.videoData)
  340. },
  341. imgUpload2(tempFilePaths) {
  342. let that = this
  343. console.log('videoUpload', tempFilePaths)
  344. let config = {
  345. AccessKeyId: 'IVW21DTGIIUBBAGXKK0Y', //AK
  346. SecretKey: 'Y01nEQNcLOATMw7uJwrk3yOdQZ2fqLhSnXcOKVDE', //SK
  347. EndPoint: 'https://horastar.obs.cn-east-3.myhuaweicloud.com', //上传文件的路径
  348. };
  349. let fileName = this.store; //指定上传到OBS桶中的对象名
  350. // let fileName = "talent_upload/icon-arrow-right.png"
  351. let OBSPolicy = { //设定policy内容
  352. "expiration": "2089-12-31T12:00:00.000Z",
  353. "conditions": [{
  354. "bucket": "horastar"
  355. }, //Bucket name
  356. // {"bucket": "goin"},
  357. {
  358. 'key': fileName
  359. }
  360. ]
  361. }
  362. let policyEncoded = getPolicyEncode(OBSPolicy); //计算policy编码值
  363. let signature = getSignature(policyEncoded, config.SecretKey); //计算signature
  364. uni.uploadFile({
  365. //url: config.EndPoint,
  366. url: config.EndPoint,
  367. filePath: tempFilePaths[0],
  368. name: 'file',
  369. formData: {
  370. 'AccessKeyID': config.AccessKeyId,
  371. 'policy': policyEncoded,
  372. 'signature': signature,
  373. 'key': fileName,
  374. },
  375. success: function(res) {
  376. console.log(res.statusCode); //打印响应状态码
  377. if (res.statusCode == '204') {
  378. that.videoData.push(config.EndPoint + '/' + fileName);
  379. console.log('上传图文成功', res)
  380. let obs_url = config.EndPoint + '/' + fileName; //用你自己的 bucket 名替换星号
  381. console.log(obs_url)
  382. // that.formData.home_img = obs_url
  383. uni.showToast({
  384. title: '上传成功',
  385. icon: '成功'
  386. });
  387. } else {
  388. console.log('上传图文失败', res)
  389. uni.showToast({
  390. title: '上传失败',
  391. icon: '失败'
  392. });
  393. }
  394. },
  395. fail: function(e) {
  396. console.log(e);
  397. uni.showToast({
  398. title: '上传失败22222',
  399. icon: '失败'
  400. });
  401. }
  402. })
  403. },
  404. guid() {
  405. return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  406. var r = Math.random() * 16 | 0,
  407. v = c == 'x' ? r : (r & 0x3 | 0x8);
  408. return v.toString(16);
  409. });
  410. },
  411. },
  412. }
  413. </script>
  414. <style>
  415. /deep/ .uni-easyinput__content-input {
  416. font-size: 30rpx !important;
  417. padding: 0 !important;
  418. }
  419. </style>
  420. <style lang="scss" scoped>
  421. .signup {
  422. box-shadow: 0rpx 5rpx 40rpx #ccc;
  423. width: 100%;
  424. position: fixed;
  425. bottom: 0rpx;
  426. display: flex;
  427. height: 90rpx;
  428. padding-top: 2%;
  429. background-color: #FFFFFF;
  430. z-index: 99;
  431. }
  432. .image-list {
  433. margin: 0 22.5rpx;
  434. display: flex;
  435. flex-wrap: wrap;
  436. // justify-content: space-between;
  437. }
  438. .image-item {
  439. width: 220rpx;
  440. height: 220rpx;
  441. margin: 10rpx 7.5rpx;
  442. }
  443. .but1 {
  444. width: 60%;
  445. background-color: #f2d22d;
  446. border-radius: 20rpx;
  447. font-size: 36rpx;
  448. line-height: 200%;
  449. letter-spacing: 10rpx;
  450. font-weight: 500;
  451. height: 80%;
  452. &.on {
  453. background-color: #C0C0C0;
  454. }
  455. }
  456. </style>