uploadsketch.vue 13 KB

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